Created
December 12, 2012 08:33
-
-
Save shoma/4266120 to your computer and use it in GitHub Desktop.
run pep8 on 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 | |
"""pre-commit-pep8.py | |
requirements | |
- pep8==1.3.3 | |
- sh==1.07 | |
in .git/hooks/pre-commit | |
#!/bin/sh | |
./pre-commit-pep8.py | |
""" | |
import re | |
import sh | |
import sys | |
def main(): | |
for f in sh.git.diff(name_only=True, _tty_out=False): | |
f = f.strip() | |
if not re.search("\.py$", f): | |
continue | |
try: | |
# pep8 --ignore=E501,E302 pre-commit-pep8.py | |
sh.pep8(f, ignore="E501") | |
except sh.ErrorReturnCode_1 as e: | |
print "found the PEP8 errors." | |
print e.stdout | |
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