Last active
October 13, 2015 22:38
-
-
Save arnaudlimbourg/4266482 to your computer and use it in GitHub Desktop.
Pre commit hook for python projects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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