Provide a quick way to run flake8

Patch copied from nova:
https://review.openstack.org/#/c/110746/

'run_tests.sh -p' always checks every file for errors.
This patch adds 'run_tests.sh -8' which only checks the files
that were modified in HEAD commit or the current working tree.

time ./run_tests.sh -p
Running flake8 ...
./glance/async/eventlet_executor.py:29:80: E501 line too
long (82 > 79 characters)

real    0m11.489s
user    0m11.342s
sys     0m0.136s

time ./run_tests.sh -8
Running flake8 on doc/source/configuring.rst
etc/glance-api.conf glance/async/eventlet_executor.py run_tests.sh
./glance/async/eventlet_executor.py:29:80: E501 line too
long (82 > 79 characters)

real    0m0.604s
user    0m0.549s
sys     0m0.059s

Change-Id: I5fa9e85da017da3989a76caf95831f3ac927d1b7
This commit is contained in:
Pawel Koniszewski 2014-12-29 02:15:36 -05:00
parent 39b6e7d2cc
commit a6943a9eda

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."
@ -42,6 +43,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;;
@ -81,6 +83,7 @@ testrargs=
testropts=
wrapper=""
just_pep8=0
just_pep8_changed=0
no_pep8=0
coverage=0
debug=0
@ -166,15 +169,17 @@ 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"
echo "Testing translation files ..."
bash -c "${wrapper} find glance -type f -regex '.*\.pot?' -print0|${wrapper} xargs --null -n 1 ${wrapper} msgfmt --check-format -o /dev/null"
}
@ -220,6 +225,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,