diff options
| author | Ian Cordasco <ian.cordasco@rackspace.com> | 2015-03-06 19:47:55 -0600 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2015-03-06 23:01:30 -0600 |
| commit | 84c8dd5e8d192a2ed6c0555a2d00164934266ba3 (patch) | |
| tree | 0c4d97e1bee0435c8a6211a80071531521a27821 /flake8/hooks.py | |
| parent | de9fd7d6a235bd2320b3aec323de783ac97e95c3 (diff) | |
| download | flake8-84c8dd5e8d192a2ed6c0555a2d00164934266ba3.tar.gz | |
Simplify @mpenkov's fix for exclude in git hooks
The simpler fix is to ensure that the filename isn't the full path to
the temporary file before we check to see if it should be excluded or if
it should even match.
This also fixes a bug I found while testing the pull request in which no
files are checked.
Diffstat (limited to 'flake8/hooks.py')
| -rw-r--r-- | flake8/hooks.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/flake8/hooks.py b/flake8/hooks.py index 1a15f0b..6687238 100644 --- a/flake8/hooks.py +++ b/flake8/hooks.py @@ -6,7 +6,7 @@ import sys import stat from subprocess import Popen, PIPE import shutil -from tempfile import mkdtemp +import tempfile try: from configparser import ConfigParser except ImportError: # Python 2 @@ -16,11 +16,6 @@ from flake8.engine import get_parser, get_style_guide from flake8.main import DEFAULT_CONFIG -def fix_exclude(flake8_style, tmpdir): - flake8_style.options.exclude = [tmpdir + x if "/" in x else x - for x in flake8_style.options.exclude] - - def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): """This is the function used by the git hook. @@ -53,11 +48,10 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): if complexity > -1: options['max_complexity'] = complexity - tmpdir = mkdtemp() + tmpdir = tempfile.mkdtemp() flake8_style = get_style_guide(config_file=DEFAULT_CONFIG, paths=['.'], **options) - fix_exclude(flake8_style, tmpdir) filepatterns = flake8_style.options.filename # Copy staged versions to temporary directory @@ -75,15 +69,16 @@ def git_hook(complexity=-1, strict=False, ignore=None, lazy=False): dirname = os.path.join(tmpdir, dirname) if not os.path.isdir(dirname): os.makedirs(dirname) - filename = os.path.join(dirname, filename) - # write staged version of file to temporary directory - with open(filename, "wb") as fh: - fh.write(out) # check_files() only does this check if passed a dir; so we do it - if ((pep8.filename_match(filename, filepatterns) and - not flake8_style.excluded(filename))): + if ((pep8.filename_match(file_, filepatterns) and + not flake8_style.excluded(file_))): + + filename = os.path.join(dirname, filename) files_to_check.append(filename) + # write staged version of file to temporary directory + with open(filename, "wb") as fh: + fh.write(out) # Run the checks report = flake8_style.check_files(files_to_check) |
