summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorent Xicluna <florent.xicluna@gmail.com>2013-02-13 19:21:37 +0100
committerFlorent Xicluna <florent.xicluna@gmail.com>2013-02-13 19:21:37 +0100
commit701ec32e3fcaf2766e44a2eae7c193a7300fd01e (patch)
tree53d3eda3a305de092ae02355830e32529ad7d15a
parent3ee195a8baf68f716df73ae6523bb490256101ae (diff)
downloadflake8-701ec32e3fcaf2766e44a2eae7c193a7300fd01e.tar.gz
Fix the commit hooks, hopefully
-rw-r--r--flake8/hooks.py48
1 files changed, 24 insertions, 24 deletions
diff --git a/flake8/hooks.py b/flake8/hooks.py
index a99bae3..cd3e126 100644
--- a/flake8/hooks.py
+++ b/flake8/hooks.py
@@ -1,52 +1,52 @@
+from __future__ import with_statement
import os
import sys
-from flake8.util import (_initpep8, pep8style, skip_file, get_parser,
- ConfigParser)
from subprocess import Popen, PIPE
+try:
+ from configparser import ConfigParser
+except ImportError: # Python 2
+ from ConfigParser import ConfigParser
+from flake8.engine import get_parser, get_style_guide
+from flake8.main import DEFAULT_CONFIG
+from flake8.util import skip_file
-def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
- from flake8.main import check_file
- _initpep8()
- if ignore:
- pep8style.options.ignore = ignore
-
- warnings = 0
+def git_hook(complexity=-1, strict=False, ignore=None, lazy=False):
gitcmd = "git diff-index --cached --name-only HEAD"
if lazy:
gitcmd = gitcmd.replace('--cached ', '')
_, files_modified, _ = run(gitcmd)
- for filename in files_modified:
- ext = os.path.splitext(filename)[-1]
- if ext != '.py':
- continue
- if not os.path.exists(filename):
- continue
- warnings += check_file(path=filename, ignore=ignore,
- complexity=complexity)
+
+ flake8_style = get_style_guide(
+ config_file=DEFAULT_CONFIG,
+ ignore=ignore, max_complexity=complexity)
+ report = flake8_style.check_files(files_modified)
if strict:
- return warnings
+ return report.get_file_results()
return 0
def hg_hook(ui, repo, **kwargs):
- from flake8.main import check_file
complexity = ui.config('flake8', 'complexity', default=-1)
config = ui.config('flake8', 'config', default=True)
- _initpep8(config_file=config)
- warnings = 0
+ if config is True:
+ config = DEFAULT_CONFIG
+
+ flake8_style = get_style_guide(
+ config_file=config,
+ max_complexity=complexity)
- for file_ in _get_files(repo, **kwargs):
- warnings += check_file(file_, complexity)
+ paths = _get_files(repo, **kwargs)
+ report = flake8_style.check_files(paths)
strict = ui.configbool('flake8', 'strict', default=True)
if strict:
- return warnings
+ return report.get_file_results()
return 0