mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +00:00
Add entry_points only with setuptools and command only w/o setuptools
This commit is contained in:
commit
bb3dcbd321
5 changed files with 826 additions and 571 deletions
2
README
2
README
|
|
@ -90,7 +90,7 @@ To use the Git hook on any *commit*, add a **pre-commit** file in the
|
|||
STRICT = False
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT))
|
||||
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT, ignore='E501'))
|
||||
|
||||
|
||||
If *strict* option is set to **True**, any warning will block the commit. When
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ except ImportError:
|
|||
|
||||
import optparse
|
||||
import sys
|
||||
from flake8.util import skip_warning
|
||||
from collections import defaultdict
|
||||
|
||||
WARNING_CODE = "W901"
|
||||
|
|
@ -243,14 +244,16 @@ def get_code_complexity(code, min=7, filename='stdin'):
|
|||
# ?
|
||||
continue
|
||||
if graph.complexity() >= min:
|
||||
msg = '%s:%d:1: %s %r is too complex (%d)' % (
|
||||
filename,
|
||||
graph.lineno,
|
||||
WARNING_CODE,
|
||||
graph.entity,
|
||||
graph.complexity(),
|
||||
)
|
||||
complex.append(msg)
|
||||
graph.filename = filename
|
||||
if not skip_warning(graph):
|
||||
msg = '%s:%d:1: %s %r is too complex (%d)' % (
|
||||
filename,
|
||||
graph.lineno,
|
||||
WARNING_CODE,
|
||||
graph.entity,
|
||||
graph.complexity(),
|
||||
)
|
||||
complex.append(msg)
|
||||
|
||||
if len(complex) == 0:
|
||||
return 0
|
||||
|
|
|
|||
1337
flake8/pep8.py
1337
flake8/pep8.py
File diff suppressed because it is too large
Load diff
|
|
@ -17,10 +17,12 @@ from flake8 import pep8
|
|||
from flake8 import pyflakes
|
||||
from flake8 import mccabe
|
||||
|
||||
pep8style = None
|
||||
|
||||
|
||||
def check_file(path, complexity=-1):
|
||||
warnings = pyflakes.checkPath(path)
|
||||
warnings += pep8.input_file(path)
|
||||
warnings += pep8style.input_file(path)
|
||||
if complexity > -1:
|
||||
warnings += mccabe.get_module_complexity(path, complexity)
|
||||
return warnings
|
||||
|
|
@ -28,7 +30,7 @@ def check_file(path, complexity=-1):
|
|||
|
||||
def check_code(code, complexity=-1):
|
||||
warnings = pyflakes.check(code, 'stdin')
|
||||
warnings += pep8.input_file(StringIO(code))
|
||||
warnings += pep8style.input_file(StringIO(code))
|
||||
if complexity > -1:
|
||||
warnings += mccabe.get_code_complexity(code, complexity)
|
||||
return warnings
|
||||
|
|
@ -51,7 +53,9 @@ def _get_python_files(paths):
|
|||
|
||||
|
||||
def main():
|
||||
options, args = pep8.process_options()
|
||||
global pep8style
|
||||
pep8style = pep8.StyleGuide(parse_argv=True, config_file=True)
|
||||
options = pep8style.options
|
||||
complexity = options.max_complexity
|
||||
builtins = set(options.builtins)
|
||||
warnings = 0
|
||||
|
|
@ -60,8 +64,8 @@ def main():
|
|||
orig_builtins = set(pyflakes._MAGIC_GLOBALS)
|
||||
pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
|
||||
|
||||
if args and options.filename is not None:
|
||||
for path in _get_python_files(args):
|
||||
if pep8style.paths and options.filename is not None:
|
||||
for path in _get_python_files(pep8style.paths):
|
||||
warnings += check_file(path, complexity)
|
||||
else:
|
||||
# wait for 1 second on the stdin fd
|
||||
|
|
@ -119,6 +123,7 @@ def _initpep8():
|
|||
pep8.options.logical_checks = pep8.find_checks('logical_line')
|
||||
pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
|
||||
pep8.options.messages = {}
|
||||
pep8.options.max_line_length = 79
|
||||
pep8.args = []
|
||||
|
||||
|
||||
|
|
@ -129,8 +134,11 @@ def run(command):
|
|||
[line.strip() for line in p.stderr.readlines()])
|
||||
|
||||
|
||||
def git_hook(complexity=-1, strict=False):
|
||||
def git_hook(complexity=-1, strict=False, ignore=None):
|
||||
_initpep8()
|
||||
if ignore:
|
||||
pep8.options.ignore=ignore
|
||||
|
||||
warnings = 0
|
||||
|
||||
_, files_modified, _ = run("git diff-index --cached --name-only HEAD")
|
||||
|
|
|
|||
19
setup.py
19
setup.py
|
|
@ -1,14 +1,24 @@
|
|||
import sys
|
||||
import sys
|
||||
|
||||
ispy3 = sys.version_info[0] == 3
|
||||
|
||||
kwargs = {}
|
||||
scripts = ["flake8/flake8"]
|
||||
if ispy3:
|
||||
from distutils.core import setup # NOQA
|
||||
else:
|
||||
try:
|
||||
from setuptools import setup # NOQA
|
||||
kwargs = {
|
||||
'tests_require': ['nose'],
|
||||
'test_suite': 'nose.collector',
|
||||
'entry_points': {
|
||||
'console_scripts': ['flake8 = flake8.run:main']
|
||||
},
|
||||
}
|
||||
except ImportError:
|
||||
from distutils.core import setup # NOQA
|
||||
scripts.append("scripts/flake8.cmd")
|
||||
|
||||
from flake8 import __version__
|
||||
|
||||
|
|
@ -23,7 +33,7 @@ setup(
|
|||
author_email="tarek@ziade.org",
|
||||
url="http://bitbucket.org/tarek/flake8",
|
||||
packages=["flake8", "flake8.tests"],
|
||||
scripts=["flake8/flake8", "scripts/flake8.cmd"],
|
||||
scripts=scripts,
|
||||
long_description=README,
|
||||
classifiers=[
|
||||
"Environment :: Console",
|
||||
|
|
@ -33,7 +43,4 @@ setup(
|
|||
"Topic :: Software Development",
|
||||
"Topic :: Utilities",
|
||||
],
|
||||
entry_points={
|
||||
'console_scripts': ['flake8 = flake8.run:main']
|
||||
},
|
||||
)
|
||||
**kwargs)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue