Instantly share code, notes, and snippets.

Embed
What would you like to do?
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