Skip to content

Commit a7471dd

Browse files
committed
tox: make it possible to run pep8 on current patch only
The 'tox -epep8' command takes a long time as it checks every single file in the Nova git repository (~1,400 at time of writing). This makes tox use a simple wrapper around flake8 which can be told to restrict the check to only files changed in the current command. This can be invoked in a simple manner with 'tox -epep8 -- -HEAD'. Since most commits only touch a handful of files, this will usually be far faster than checking all 1,400 source files. To check an entire branch for bisectability it can be automated via git rebase -i master -x 'tox -epep8 -- -HEAD' Change-Id: I157d1ccb883ca02402eee51fd7d6a50f86079389
1 parent 0d696ad commit a7471dd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tools/flake8wrap.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
#
3+
# A simple wrapper around flake8 which makes it possible
4+
# to ask it to only verify files changed in the current
5+
# git HEAD patch.
6+
#
7+
# Intended to be invoked via tox:
8+
#
9+
# tox -epep8 -- -HEAD
10+
#
11+
12+
if test "x$1" = "x-HEAD" ; then
13+
shift
14+
files=$(git diff --name-only HEAD~1 | tr '\n' ' ')
15+
echo "Running flake8 on ${files}"
16+
diff -u --from-file /dev/null ${files} | flake8 --diff "$@"
17+
else
18+
echo "Running flake8 on all files"
19+
exec flake8 "$@"
20+
fi

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ downloadcache = ~/cache/pip
2727

2828
[testenv:pep8]
2929
commands =
30-
flake8 {posargs}
30+
bash tools/flake8wrap.sh {posargs}
3131

3232
[testenv:py34]
3333
setenv = {[testenv]setenv}

0 commit comments

Comments
 (0)