diff options
Diffstat (limited to 'flake8')
| -rw-r--r-- | flake8/pep8.py | 2 | ||||
| -rw-r--r-- | flake8/run.py | 20 |
2 files changed, 14 insertions, 8 deletions
diff --git a/flake8/pep8.py b/flake8/pep8.py index 1ecb566..2eeee6d 100644 --- a/flake8/pep8.py +++ b/flake8/pep8.py @@ -1264,6 +1264,8 @@ def process_options(arglist=None): global options, args parser = OptionParser(version=__version__, usage="%prog [options] input ...") + parser.add_option('--max-complexity', default=-1, action='store', + type='int', help="McCabe complexity treshold") parser.add_option('-v', '--verbose', default=0, action='count', help="print status messages, or debug with -vv") parser.add_option('-q', '--quiet', default=0, action='count', diff --git a/flake8/run.py b/flake8/run.py index ddc0ea1..d3a803c 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -12,16 +12,18 @@ from flake8 import pyflakes from flake8 import mccabe -def check_file(path, complexity=10): +def check_file(path, complexity=-1): warnings = pyflakes.checkPath(path) warnings += pep8.input_file(path) - warnings += mccabe.get_module_complexity(path, complexity) + if complexity > -1: + warnings += mccabe.get_module_complexity(path, complexity) return warnings -def check_code(code, complexity=10): +def check_code(code, complexity=-1): warnings = pyflakes.check(code, '<stdin>') - warnings += mccabe.get_code_complexity(code, complexity) + if complexity > -1: + warnings += mccabe.get_code_complexity(code, complexity) return warnings @@ -43,13 +45,14 @@ def _get_python_files(paths): def main(): options, args = pep8.process_options() + complexity = options.max_complexity warnings = 0 if args: for path in _get_python_files(args): - warnings += check_file(path) + warnings += check_file(path, complexity) else: stdin = sys.stdin.read() - warnings += check_code(stdin) + warnings += check_code(stdin, complexity) raise SystemExit(warnings > 0) @@ -84,10 +87,11 @@ def hg_hook(ui, repo, **kwargs): pep8.options.physical_checks = pep8.find_checks('physical_line') pep8.options.logical_checks = pep8.find_checks('logical_line') pep8.args = [] - + complexity = ui.configint('flake8', 'complexity', default=-1) warnings = 0 + for file_ in _get_files(repo, **kwargs): - warnings += check_file(file_) + warnings += check_file(file_, complexity) strict = ui.configbool('flake8', 'strict', default=True) |
