Skip to content

Instantly share code, notes, and snippets.

@arnaudlimbourg
Last active October 13, 2015 22:38
Show Gist options
  • Save arnaudlimbourg/4266482 to your computer and use it in GitHub Desktop.
Save arnaudlimbourg/4266482 to your computer and use it in GitHub Desktop.
Pre commit hook for python projects
#!/bin/sh
CHANGED=`git diff --cached --name-only --diff-filter=ACM | grep ".py"`
if [ -z "$CHANGED" ]; then
exit 0
fi
# run tests
# TESTS=`py.test ferpection`
# if [ $TESTS -ne 0 ]; then
# echo "your tests failed"
# exit 1
# fi
# Check if there is no print in the code
/usr/local/bin/ag --python -1 "\bprint" $CHANGED >/dev/null 2>&1
if [ "$?" -ne "1" ]; then
echo "There is a print in your code :"
ag --python --nocolor --noheading print $CHANGED
exit 1
fi
# Check if the code pass pep8 and pyflakes tests
/usr/local/bin/flake8 --ignore=E501 --count $CHANGED >/dev/null 2>&1
if [ "$?" -ne "0" ]; then
echo "Your code doesn't pass QA tests :"
/usr/local/bin/flake8 --ignore=E501 --count $CHANGED
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment