-
-
Save ento/4730296 to your computer and use it in GitHub Desktop.
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 | |
in .git/hooks/pre-commit | |
#!/bin/sh | |
./path/to/this/script/in/your/repo/pre-commit-pep8.py | |
""" | |
import re | |
import sys | |
import commands | |
ignores = ('E501', ) | |
def main(): | |
has_errors = False | |
for f in commands.getoutput('git diff --cached --name-only').split(): | |
f = f.strip() | |
if not re.search("\.py$", f): | |
continue | |
command = 'pep8 --ignore={codes} {0}'.format(f, codes=','.join(ignores)) | |
status, output = commands.getstatusoutput(command) | |
if status != 0: | |
has_errors = True | |
print output | |
if has_errors: | |
print '--' | |
print 'Fix these pep8 errors before committing.' | |
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