mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 15:24:18 +00:00
Merged in harobed/flake8 (pull request #20)
This commit is contained in:
commit
35c2d8b3ae
2 changed files with 796 additions and 555 deletions
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 pyflakes
|
||||||
from flake8 import mccabe
|
from flake8 import mccabe
|
||||||
|
|
||||||
|
pep8style = None
|
||||||
|
|
||||||
|
|
||||||
def check_file(path, complexity=-1):
|
def check_file(path, complexity=-1):
|
||||||
warnings = pyflakes.checkPath(path)
|
warnings = pyflakes.checkPath(path)
|
||||||
warnings += pep8.input_file(path)
|
warnings += pep8style.input_file(path)
|
||||||
if complexity > -1:
|
if complexity > -1:
|
||||||
warnings += mccabe.get_module_complexity(path, complexity)
|
warnings += mccabe.get_module_complexity(path, complexity)
|
||||||
return warnings
|
return warnings
|
||||||
|
|
@ -28,7 +30,7 @@ def check_file(path, complexity=-1):
|
||||||
|
|
||||||
def check_code(code, complexity=-1):
|
def check_code(code, complexity=-1):
|
||||||
warnings = pyflakes.check(code, 'stdin')
|
warnings = pyflakes.check(code, 'stdin')
|
||||||
warnings += pep8.input_file(StringIO(code))
|
warnings += pep8style.input_file(StringIO(code))
|
||||||
if complexity > -1:
|
if complexity > -1:
|
||||||
warnings += mccabe.get_code_complexity(code, complexity)
|
warnings += mccabe.get_code_complexity(code, complexity)
|
||||||
return warnings
|
return warnings
|
||||||
|
|
@ -51,7 +53,9 @@ def _get_python_files(paths):
|
||||||
|
|
||||||
|
|
||||||
def main():
|
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
|
complexity = options.max_complexity
|
||||||
builtins = set(options.builtins)
|
builtins = set(options.builtins)
|
||||||
warnings = 0
|
warnings = 0
|
||||||
|
|
@ -60,8 +64,8 @@ def main():
|
||||||
orig_builtins = set(pyflakes._MAGIC_GLOBALS)
|
orig_builtins = set(pyflakes._MAGIC_GLOBALS)
|
||||||
pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
|
pyflakes._MAGIC_GLOBALS = orig_builtins | builtins
|
||||||
|
|
||||||
if args and options.filename is not None:
|
if pep8style.paths and options.filename is not None:
|
||||||
for path in _get_python_files(args):
|
for path in _get_python_files(pep8style.paths):
|
||||||
warnings += check_file(path, complexity)
|
warnings += check_file(path, complexity)
|
||||||
else:
|
else:
|
||||||
# wait for 1 second on the stdin fd
|
# wait for 1 second on the stdin fd
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue