diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh new file mode 100755 index 0000000000..531b407d6a --- /dev/null +++ b/tools/flake8wrap.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# A simple wrapper around flake8 which makes it possible +# to ask it to only verify files changed in the current +# git HEAD patch. +# +# Intended to be invoked via tox: +# +# tox -epep8 -- -HEAD +# + +if test "x$1" = "x-HEAD" ; then + shift + files=$(git diff --name-only HEAD~1 | tr '\n' ' ') + echo "Running flake8 on ${files}" + diff -u --from-file /dev/null ${files} | flake8 --diff "$@" +else + echo "Running flake8 on all files" + exec flake8 "$@" +fi diff --git a/tox.ini b/tox.ini index 8b8fc53380..61f95b5339 100644 --- a/tox.ini +++ b/tox.ini @@ -25,7 +25,7 @@ commands = {toxinidir}/tools/states_to_dot.py -f {toxinidir}/doc/source/images/s [testenv:pep8] whitelist_externals = bash commands = - flake8 {posargs} + bash tools/flake8wrap.sh {posargs} # Run bashate during pep8 runs to ensure violations are caught by # the check and gate queues. {toxinidir}/tools/run_bashate.sh {toxinidir}/devstack