Skip to content

Instantly share code, notes, and snippets.

@4383
Forked from zaneb/fast8.sh
Created June 21, 2019 08:06
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 4383/34b9456076c929144d6c5789e3635351 to your computer and use it in GitHub Desktop.
Save 4383/34b9456076c929144d6c5789e3635351 to your computer and use it in GitHub Desktop.
Run flake8 against only files that have changed
#!/bin/bash
set -e
enable_env() {
local env_name="$1"
local env_dir=".tox/${env_name}"
if [ ! -d "${env_dir}" ]; then
if [ ! -f tox.ini ]; then
echo 'No tox.ini found' >&2
exit 1
elif tox -l | grep -q "^${env_name}$$"; then
tox -e"${env_name}" --notest
else
echo "No ${env_name} tox environment found" >&2
exit 1
fi
fi
source "${env_dir}"/bin/activate
}
diff_files_branch() {
local branch=${1:-"@{u}"}
git diff --name-only --diff-filter=d "${branch}" -- '*.py'
}
diff_files() {
diff_files_branch 2>/dev/null || diff_files_branch origin/master
}
enable_env pep8
flake8 $(diff_files)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment