Created
June 20, 2019 17:12
-
-
Save zaneb/7a8c752bfd97dd8972756d296fc5e41f to your computer and use it in GitHub Desktop.
Run flake8 against only files that have changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Ahh okay somehow I missed the '||' my mistake
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It does use
@{u}
(see line 23) and only falls back toorigin/master
if that fails. So it does the Right Thing on stable branches and falls back to diffing against master if you're working on e.g. a detached HEAD.