public
Created — forked from steder/pre-commit.py

Git Pre-commit Hook For Python now with extra Python!

  • Download Gist
pre-commit.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/env python
#-*- mode: python -*-
 
from subprocess import Popen, PIPE
import sys
 
syntax_checker = "pyflakes"
 
def run(command):
p = Popen(command.split(), stdout=PIPE, stderr=PIPE)
p.wait()
return p.returncode, p.stdout.read().strip().split(), p.stderr.read()
 
_, files_modified, _= run("git diff-index --name-only HEAD")
 
for fname in files_modified:
if fname.endswith(".py"):
print >>sys.stderr, "Checking syntax on %s: ... "%(fname,),
exit_code, _, errors = run("%s %s"%(syntax_checker, fname))
if exit_code != 0:
print >>sys.stderr, "\rChecking syntax on %s: FAILED! "%(fname,)
sys.exit(exit_code)
else:
print >>sys.stderr, "\rChecking syntax on %s: OK!"%(fname,)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.