Skip to content

Instantly share code, notes, and snippets.

@drichardson
Created December 16, 2020 21:20
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 drichardson/e51c8f30eda079f732eb42ed95f8e2e1 to your computer and use it in GitHub Desktop.
Save drichardson/e51c8f30eda079f732eb42ed95f8e2e1 to your computer and use it in GitHub Desktop.
git pre-commit hook script to run pycodestyle to check for PEP-8 conformance
#!/bin/sh
# Is pycodestyle is installed?
which pycodestyle &> /dev/null
if [[ $? -ne 0 ]]; then
cat <<-EOF
pre-commit hook failed. pycodestyle is not installed.
Run the following and try your commit again:
pip install pycodestyle
EOF
exit 1
fi
# Run pycodestyle to check pep8 conformance.
pycodestyle
if [[ $? -ne 0 ]]; then
echo pycodestyle failed in pre-commit hook.
echo Fix errors and retry commit.
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment