Skip to content

Instantly share code, notes, and snippets.

@kunev
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunev/11377872 to your computer and use it in GitHub Desktop.
Save kunev/11377872 to your computer and use it in GitHub Desktop.
python pre-commit hook
#!/bin/sh
# Get all the python files staged for committing
py_files=`git diff --name-only HEAD|grep '.py$'`
# If we;re trying to commit a pdb.set_trace() display an error message and exit right away with status 1
grep -n 'pdb.set_trace()' $py_files && echo -e "\033[1;31m Debugger statements!!!\033[0m" && exit 1
# Run pyflakes on all the files beign committed and exit with status 0 if there are no errors, else show error message
pyflakes $py_files && exit || echo -e "\033[1;31m Lint error!\033[0m"
# If we’re here, then pyflakes failed, exit with status 1
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment