From ccc7acc62e22ec7a1a97197fbbe208ded25936e8 Mon Sep 17 00:00:00 2001 From: onlytiancai Date: Wed, 12 Sep 2012 11:03:20 +0800 Subject: [PATCH] 1. mccabe.py support # NOQA 2. run.py support ignore some errors 3. run.py add max_line_length default value --- README | 2 +- flake8/mccabe.py | 19 +++++++++++-------- flake8/run.py | 6 +++++- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/README b/README index 379c174..ae235dd 100644 --- a/README +++ b/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 diff --git a/flake8/mccabe.py b/flake8/mccabe.py index 4dcb5bd..d998d0e 100644 --- a/flake8/mccabe.py +++ b/flake8/mccabe.py @@ -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 diff --git a/flake8/run.py b/flake8/run.py index 649f7b9..f159bbd 100644 --- a/flake8/run.py +++ b/flake8/run.py @@ -119,6 +119,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 +130,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")