Skip to content

Instantly share code, notes, and snippets.

@squamous
Last active January 24, 2017 04:26
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 squamous/8501228069a360fcd219930c14d55ccc to your computer and use it in GitHub Desktop.
Save squamous/8501228069a360fcd219930c14d55ccc to your computer and use it in GitHub Desktop.
Pre-commit git hook to lint all python files
#!/bin/sh
# works as of flake8 3.2.1
echo -n "Enter the project directory and press [Enter]: "
read project
if [ ! -d $project ]; then
echo "FAILURE: Could not find directory '$project'"
fi
cd $project
echo '* Installing flake8 git pre-commit hook\n'
flake8 --install-hook git
echo "* configuring flake8 to forbid commits containing errors/warnings\n"
git config --bool flake8.strict true
echo "* setting some flake8 config options in your project's tox.ini"
cat << 'EOF' >> tox.ini
[flake8]
max-line-length = 120
ignore = F403
exclude = *migrations*,venv
EOF
tail -n 4 tox.ini
echo '\n* Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment