Provide a quick way to run flake8

"run_tests.sh -p" always checks every file for errors even though you
have probably only changed a handful. This patch adds "run_tests.sh -8"
which only checks the files that were modified in the HEAD commit or
the current working tree.

An unscientific benchmark shows that this can be quite a bit faster:

Before:
$ time ./run_tests.sh -p
Running flake8 ...
./nova/compute/manager.py:77:1: F401 'periodic_task' imported but unused

real    0m37.493s
user    0m37.391s
sys     0m0.099s

After:
$ time ./run_tests.sh -8
Running flake8 on nova/compute/manager.py
./nova/compute/manager.py:77:1: F401 'periodic_task' imported but unused

real    0m0.667s
user    0m0.624s
sys     0m0.036s

Change-Id: I8dafaab40fd0427719040a76c69a8ab05e9e4386
This commit is contained in:
Matthew Gilliard 2014-07-30 19:27:13 +01:00
parent f48827dcfa
commit b011325cc6
1 changed files with 24 additions and 4 deletions

View File

@ -12,6 +12,7 @@ function usage {
echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added."
echo " -u, --update Update the virtual environment with any newer package versions"
echo " -p, --pep8 Just run PEP8 and HACKING compliance check"
echo " -8, --pep8-only-changed Just run PEP8 and HACKING compliance check on files changed since HEAD~1"
echo " -P, --no-pep8 Don't run static code checks"
echo " -c, --coverage Generate coverage report"
echo " -d, --debug Run tests with testtools instead of testr. This allows you to use the debugger."
@ -43,6 +44,7 @@ function process_options {
-f|--force) force=1;;
-u|--update) update=1;;
-p|--pep8) just_pep8=1;;
-8|--pep8-only-changed) just_pep8_changed=1;;
-P|--no-pep8) no_pep8=1;;
-c|--coverage) coverage=1;;
-d|--debug) debug=1;;
@ -82,6 +84,7 @@ testrargs=
testropts=
wrapper=""
just_pep8=0
just_pep8_changed=0
no_pep8=0
coverage=0
debug=0
@ -167,12 +170,16 @@ function copy_subunit_log {
cp $LOGNAME subunit.log
}
function warn_on_flake8_without_venv {
if [ $never_venv -eq 1 ]; then
echo "**WARNING**:"
echo "Running flake8 without virtual env may miss OpenStack HACKING detection"
fi
}
function run_pep8 {
echo "Running flake8 ..."
if [ $never_venv -eq 1 ]; then
echo "**WARNING**:"
echo "Running flake8 without virtual env may miss OpenStack HACKING detection"
fi
warn_on_flake8_without_venv
bash -c "${wrapper} flake8"
}
@ -219,6 +226,19 @@ if [ $just_pep8 -eq 1 ]; then
exit
fi
if [ $just_pep8_changed -eq 1 ]; then
# NOTE(gilliard) We want use flake8 to check the entirety of every file that has
# a change in it. Unfortunately the --filenames argument to flake8 only accepts
# file *names* and there are no files named (eg) "nova/compute/manager.py". The
# --diff argument behaves surprisingly as well, because although you feed it a
# diff, it actually checks the file on disk anyway.
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
echo "Running flake8 on ${files}"
warn_on_flake8_without_venv
bash -c "diff -u --from-file /dev/null ${files} | ${wrapper} flake8 --diff"
exit
fi
run_tests
# NOTE(sirp): we only want to run pep8 when we're running the full-test suite,