From 0d3cc25400c771d3f7f24ef8bb3e6d585852b5c6 Mon Sep 17 00:00:00 2001 From: John Watson Date: Tue, 8 Jan 2013 20:33:50 -0800 Subject: [PATCH 1/3] Clear os.walk's dirnames to properly exclude dirs I have a project: `./foo/__init__.py` `./foo/bar/__init__.py` `./foo/baz.py` `./__init__.py` `./qux.py` Running: `flake8 --exclude="foo" ./` Checks: `./foo/bar/__init__.py` `./__init__.py` `./qux.py` This patch prevents the continued walking of **foo**'s subdirectories and not just files. --- flake8/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flake8/main.py b/flake8/main.py index 9e462aa..faac93b 100644 --- a/flake8/main.py +++ b/flake8/main.py @@ -141,6 +141,7 @@ def _get_python_files(paths): if os.path.isdir(path): for dirpath, dirnames, filenames in os.walk(path): if pep8style.excluded(dirpath): + dirnames[:] = [] continue for filename in filenames: if not filename.endswith('.py'): From 8eec1e5e116feaaa1587a37b5974d664728fff51 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Wed, 9 Jan 2013 11:26:00 -0500 Subject: [PATCH 2/3] Fixes #57 Don't allow for ignore to be None --- flake8/util.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/flake8/util.py b/flake8/util.py index 49042d6..c8188ce 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -49,8 +49,9 @@ def get_parser(): def skip_warning(warning, ignore=[]): # XXX quick dirty hack, just need to keep the line in the warning - if not hasattr(warning, 'message'): + if not hasattr(warning, 'message') or ignore is None: # McCabe's warnings cannot be skipped afaik, and they're all strings. + # And we'll get a TypeError otherwise return False if warning.message.split()[0] in ignore: return True From e236b7f6b33590b49b87462b199d16fee2e8fd55 Mon Sep 17 00:00:00 2001 From: Kevin Stanton Date: Wed, 9 Jan 2013 11:31:41 -0500 Subject: [PATCH 3/3] Add support for the pep8 config file Closes #55. --- flake8/hooks.py | 3 ++- flake8/util.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/flake8/hooks.py b/flake8/hooks.py index 7d493b8..a99bae3 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -35,8 +35,9 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): def hg_hook(ui, repo, **kwargs): from flake8.main import check_file - _initpep8() complexity = ui.config('flake8', 'complexity', default=-1) + config = ui.config('flake8', 'config', default=True) + _initpep8(config_file=config) warnings = 0 for file_ in _get_files(repo, **kwargs): diff --git a/flake8/util.py b/flake8/util.py index c8188ce..8d78edb 100644 --- a/flake8/util.py +++ b/flake8/util.py @@ -91,16 +91,17 @@ def skip_file(path, source=None): return _NOQA.search(content) is not None -def _initpep8(): +def _initpep8(config_file=True): # default pep8 setup global pep8style import pep8 if pep8style is None: - pep8style = pep8.StyleGuide(config_file=True) + pep8style = pep8.StyleGuide(config_file=config_file) pep8style.options.physical_checks = pep8.find_checks('physical_line') pep8style.options.logical_checks = pep8.find_checks('logical_line') pep8style.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0) pep8style.options.messages = {} - pep8style.options.max_line_length = 79 + if not pep8style.options.max_line_length: + pep8style.options.max_line_length = 79 pep8style.args = [] return pep8style