diff options
author | David Cramer <dcramer@gmail.com> | 2013-09-14 09:27:50 +0900 |
---|---|---|
committer | David Cramer <dcramer@gmail.com> | 2013-09-14 09:28:04 +0900 |
commit | 6636eb700f555be515442b35e4af7155e17b4c96 (patch) | |
tree | 8c37b563a418bf4b24dd0f6be2d74282bbfed053 | |
parent | c0362c6025f54312acc9cc0954e7dfed0852a189 (diff) | |
download | raven-6636eb700f555be515442b35e4af7155e17b4c96.tar.gz |
Force rebase and precommit flake8
-rw-r--r-- | Makefile | 5 | ||||
-rwxr-xr-x | hooks/pre-commit | 39 | ||||
-rwxr-xr-x | setup.py | 2 |
3 files changed, 45 insertions, 1 deletions
@@ -2,6 +2,7 @@ bootstrap: pip install -e . --use-mirrors pip install "file://`pwd`#egg=raven[dev]" --use-mirrors pip install "file://`pwd`#egg=raven[tests]" --use-mirrors + make setup-git test: bootstrap lint @echo "Running Python tests" @@ -16,3 +17,7 @@ lint: coverage: coverage run runtests.py --include=raven/* && \ coverage html --omit=*/migrations/* -d cover + +setup-git: + git config branch.autosetuprebase always + cd .git/hooks && ln -sf ../../hooks/* ./ diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..d58db4d --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import glob +import os +import sys + +os.environ['PYFLAKES_NODOCTEST'] = '1' + +# pep8.py uses sys.argv to find setup.cfg +sys.argv = [os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)] + +# git usurbs your bin path for hooks and will always run system python +if 'VIRTUAL_ENV' in os.environ: + site_packages = glob.glob( + '%s/lib/*/site-packages' % os.environ['VIRTUAL_ENV'])[0] + sys.path.insert(0, site_packages) + + +def main(): + from flake8.main import DEFAULT_CONFIG + from flake8.engine import get_style_guide + from flake8.hooks import run + + gitcmd = "git diff-index --cached --name-only HEAD" + + _, files_modified, _ = run(gitcmd) + + # remove non-py files and files which no longer exist + files_modified = filter( + lambda x: x.endswith('.py') and os.path.exists(x), + files_modified) + + flake8_style = get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG) + report = flake8_style.check_files(files_modified) + + return report.total_errors + +if __name__ == '__main__': + sys.exit(main()) @@ -29,7 +29,7 @@ setup_requires = [ ] dev_requires = [ - 'flake8>=1.6,<2.0', + 'flake8>=2.0,<2.1', ] unittest2_requires = ['unittest2'] |