Skip to content

Instantly share code, notes, and snippets.

@hvelarde
Created June 5, 2012 22:14
Show Gist options
  • Save hvelarde/2878450 to your computer and use it in GitHub Desktop.
Save hvelarde/2878450 to your computer and use it in GitHub Desktop.
PEP 8 pre-commit hook
#!/bin/sh
# Modified from kevincal version in https://gist.github.com/810399
# The following is a list of the most common PEP 8 errors and warnings; to
# skip some just add them to the IGNORE variable (comma separated):
# E111 indentation is not a multiple of four
# E123 closing bracket does not match indentation of opening bracket's line
# E201 whitespace after '('
# E202 whitespace before ')'
# E203 whitespace before ','
# E211 whitespace before '('
# E221 multiple spaces before operator
# E222 multiple spaces after operator
# E225 missing whitespace around operator
# E231 missing whitespace after ':'
# E251 no spaces around keyword / parameter equals
# E261 at least two spaces before inline comment
# E271 multiple spaces after keyword
# E272 multiple spaces before keyword
# E301 expected 1 blank line, found 0
# E302 expected 2 blank lines, found 1
# E303 too many blank lines (3)
# E401 multiple imports on one line
# E501 line too long (80 characters)
# E701 multiple statements on one line (colon)
# W291 trailing whitespace
# W293 blank line contains whitespace
# W391 blank line at end of file
# W601 .has_key() is deprecated, use 'in'
# W602 deprecated form of raising exception
# W604 backticks are deprecated, use 'repr()'
IGNORE=E123,E501,E701
FILES=$(git diff --cached --name-status | grep -v ^D | awk '$1 $2 { print $2}' | grep -e .py$)
if [ -n "$FILES" ]; then
pep8 --ignore $IGNORE $FILES
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment