From 218949a3aac6142be86ac242a18873f5ddf67864 Mon Sep 17 00:00:00 2001 From: Michael Penkov Date: Tue, 11 Nov 2014 21:15:58 +0900 Subject: [PATCH] Correctly handle exclude patterns in git_hook --- flake8/hooks.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/flake8/hooks.py b/flake8/hooks.py index 1cbe884..7c7cd94 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -48,12 +48,20 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): if complexity > -1: options['max_complexity'] = complexity + tmpdir = mkdtemp() + flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'], **options) + # If an exclude pattern contains a slash, then pep8.read_config will + # convert it to an absolute path, using os.curdir as a base. This behavior + # causes pep8.filename_match to fail, since our files will be + # in tmpdir, not os.curdir. The workaround below corrects this problem. + flake8_style.options.exclude = [tmpdir + x if "/" in x else x + for x in flake8_style.options.exclude] + filepatterns = flake8_style.options.filename # Copy staged versions to temporary directory - tmpdir = mkdtemp() files_to_check = [] try: for file_ in files_modified: