Skip to content

Instantly share code, notes, and snippets.

@cyeong
Forked from milancermak/pre-commit.sh
Created December 10, 2012 08:30
Show Gist options
  • Save cyeong/4249344 to your computer and use it in GitHub Desktop.
Save cyeong/4249344 to your computer and use it in GitHub Desktop.
Python pre-commit hook
#!/bin/sh
# make sure requirements.txt is up to date with every commit
# by comparing the output of pip freeze
pip freeze | diff requirements.txt - > /dev/null
if [ $? != 0 ]
then
echo "Missing python module dependencies in requirements.txt. Run 'pip freeze > requirements.txt' to update."
exit 1
fi
# run pyflakes on all the python source files in the repo
FAULTS=$(find ./* -iname "*.py" -exec pyflakes {} \; 2>&1 | grep -c -v "undefined name '_'")
if [ $FAULTS != 0 ]
then
find ./* -iname "*.py" -exec pyflakes {} \; 2>&1 | grep -v "undefined name '_'"
#exit 1
fi
# check for forgotten set_trace()
grep -n 'set_trace()' `find ./* -iname '*.py'` && exit 1 || exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment