Skip to content

Instantly share code, notes, and snippets.

@bartek
Forked from pbhandari/pre-commit
Created December 10, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartek/44525cbbc8394f65478eb3094521961f to your computer and use it in GitHub Desktop.
Save bartek/44525cbbc8394f65478eb3094521961f to your computer and use it in GitHub Desktop.
pre commit hook for running pylint
#!/bin/sh
DESIRED_VENV=compass
if [ -z $VIRTUAL_ENV ] || [ "`basename $VIRTUAL_ENV`" != "$DESIRED_VENV" ]; then
echo You\'re not in the $DESIRED_VENV virtualenv, \`workon $DESIRED_VENV\` to fix.
exit 1
fi
RCFILE="`git rev-parse --show-toplevel`"/.pylintrc
[ -e "$RCFILE" ] || echo "Cannot find $RCFILE"
FILES=`git diff-index --cached HEAD | awk '{ printf $6" " }'`
if [ -z "$FILES" ]; then
echo "Nothing to commit"
exit 1
fi
COMMAND="pylint --rcfile='$RCFILE' $FILES"
OUTPUT="`$COMMAND 2>&1`"
echo $COMMAND
echo "$OUTPUT"
echo "$OUTPUT" | awk '/^E:/ { exit 1 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment