Skip to content

Instantly share code, notes, and snippets.

@splanquart
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splanquart/8872168 to your computer and use it in GitHub Desktop.
Save splanquart/8872168 to your computer and use it in GitHub Desktop.
pre-commit git hook to run flask before each commit
#!/usr/bin/python
import sys
from flake8.engine import get_style_guide as get_style_guide
import os
import shutil
from tempfile import mkdtemp
from flake8.main import DEFAULT_CONFIG
COMPLEXITY = 10
STRICT = True
IGNORE = ['E501']
# before install tip this line out of your virtual env and install flake8
# sudo pip install flake8
# you can install it from command line by tip this line
# curl -o pre-commit https://gist.github.com/splanquart/8872168/raw; chmod +x pre-commit ;mv pre-commit .git/hooks/
# patch flake8 git_hook
def get_style_guide2(**kwargs):
del kwargs['parse_argv']
return get_style_guide(**kwargs)
import flake8.hooks
flake8.hooks.get_style_guide = get_style_guide2
from flake8.hooks import git_hook
if __name__ == '__main__':
sys.exit(git_hook(complexity=COMPLEXITY, strict=STRICT, ignore=IGNORE))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment