Skip to content

Instantly share code, notes, and snippets.

@dwf
Last active December 14, 2015 08:49
Show Gist options
  • Save dwf/5060608 to your computer and use it in GitHub Desktop.
Save dwf/5060608 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Run pyflakes on all changed .py files before commit.
#
# By David Warde-Farley, Feb 28, 2013 -- released under the 3-clause BSD license.
#
# To use, run this file from the script .git/hooks/pre-commit
FILES=`git diff --staged --name-status |grep '\.py$' |grep '^[AM]' |sed -e's/^[AM]\s\+//'`
ROOT=`git rev-parse --show-toplevel`
NUM_BAD_FILES=0
for fn in $FILES; do
pyflakes $ROOT/$fn
STATUS=$?
if [ $STATUS ]; then
NUM_BAD_FILES=`expr $NUM_BAD_FILES + 1`
fi
done
if [ $NUM_BAD_FILES -gt 0 ]; then
echo "! Aborting commit; pyflakes errors in $NUM_BAD_FILES staged file(s)."
exit $NUM_BAD_FILES
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment