From 39e60d42544a75589b05fdb5855a03f0e073de08 Mon Sep 17 00:00:00 2001 From: Florian Rathgeber Date: Sun, 23 Mar 2014 18:47:21 +0000 Subject: [PATCH 1/3] Default hg ignore config to empty instead of None Setting it to None is interpreted as the string 'None', which does the wrong thing. Setting it to the empty string gives the right behaviour and allows overriding in config files. --- flake8/hooks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake8/hooks.py b/flake8/hooks.py index 5173883..3249dcf 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -217,7 +217,7 @@ def _install_hg_hook(path): c.set('flake8', 'strict', os.getenv('FLAKE8_STRICT', False)) if not c.has_option('flake8', 'ignore'): - c.set('flake8', 'ignore', os.getenv('FLAKE8_IGNORE')) + c.set('flake8', 'ignore', os.getenv('FLAKE8_IGNORE', '')) if not c.has_option('flake8', 'lazy'): c.set('flake8', 'lazy', os.getenv('FLAKE8_LAZY', False)) From b0499123171ade5c472fba46ee711411f1d5fa2c Mon Sep 17 00:00:00 2001 From: Florian Rathgeber Date: Sun, 23 Mar 2014 18:52:00 +0000 Subject: [PATCH 2/3] Pass current directory as paths to pep8 StyleGuide Instead of setting parse_argv to True, which fails if no config files are present, we pass the current directory as the paths keyword argument when creating the pep8 StyleGuide. This causes pep8 to parse local config files as expected and works also if none are present. Requires pep8 68d72a5d or newer. --- flake8/hooks.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/flake8/hooks.py b/flake8/hooks.py index 3249dcf..403dcf9 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -55,11 +55,8 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): files_modified = [f for f in files_modified if f.endswith('.py')] - flake8_style = get_style_guide( - parse_argv=True, - config_file=DEFAULT_CONFIG, - **options - ) + flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'], + **options) # Copy staged versions to temporary directory tmpdir = mkdtemp() @@ -117,7 +114,7 @@ def hg_hook(ui, repo, **kwargs): if complexity > -1: options['max_complexity'] = complexity - flake8_style = get_style_guide(parse_argv=True, config_file=config, + flake8_style = get_style_guide(config_file=config, paths=['.'], **options) report = flake8_style.check_files(paths) From f678e5daee203111aa96209dfca331ded39a69f5 Mon Sep 17 00:00:00 2001 From: Florian Rathgeber Date: Sun, 23 Mar 2014 18:52:35 +0000 Subject: [PATCH 3/3] Minor hg hook refactoring --- flake8/hooks.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/flake8/hooks.py b/flake8/hooks.py index 403dcf9..c84c382 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -100,9 +100,7 @@ def hg_hook(ui, repo, **kwargs): complexity = ui.config('flake8', 'complexity', default=-1) strict = ui.configbool('flake8', 'strict', default=True) ignore = ui.config('flake8', 'ignore', default=None) - config = ui.config('flake8', 'config', default=True) - if config is True: - config = DEFAULT_CONFIG + config = ui.config('flake8', 'config', default=DEFAULT_CONFIG) paths = _get_files(repo, **kwargs)