Skip to content

Commit

Permalink
Force rebase and precommit flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Sep 14, 2013
1 parent c0362c6 commit 6636eb7
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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/* ./
39 changes: 39 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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())
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
]

dev_requires = [
'flake8>=1.6,<2.0',
'flake8>=2.0,<2.1',
]

unittest2_requires = ['unittest2']
Expand Down

0 comments on commit 6636eb7

Please sign in to comment.