Skip to content

Instantly share code, notes, and snippets.

@milancermak
Created October 7, 2012 19:24
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save milancermak/3849310 to your computer and use it in GitHub Desktop.
Save milancermak/3849310 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
@DominiquePaul
Copy link

Is it somehow to add this to a .pre-commit-config.yaml file by referencing it or do I have to copy the file into my repository?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment