Created
March 27, 2014 21:16
-
-
Save veloutin/9819066 to your computer and use it in GitHub Desktop.
flake8 git pre-commit hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# inspired by http://tech.myemma.com/python-pep8-git-hooks/ | |
from __future__ import with_statement | |
import re | |
import subprocess | |
import sys | |
def system(*args, **kwargs): | |
kwargs.setdefault('stdout', subprocess.PIPE) | |
proc = subprocess.Popen(args, **kwargs) | |
out, err = proc.communicate() | |
return out | |
def main(): | |
modified = re.compile('^[AM]+\s+(?P<name>.*\.py)', re.MULTILINE) | |
files = system('git', 'status', '--porcelain') | |
files = modified.findall(files) | |
output = system('flake8', "--ignore=E501,F401", *files) | |
if output: | |
print output, | |
sys.exit(1) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment