Skip to content

Instantly share code, notes, and snippets.

@ento
Forked from shoma/pre-commit-pep8.py
Last active December 12, 2015 06:38
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 ento/4730296 to your computer and use it in GitHub Desktop.
Save ento/4730296 to your computer and use it in GitHub Desktop.
#!/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