From 800c3dbf93eab4411b78c8e38f56f1f0b8003233 Mon Sep 17 00:00:00 2001 From: Arnaud M Date: Sun, 6 Oct 2024 11:20:20 +0200 Subject: [PATCH] Add fast8 tox env This was taken from the nova project, fast8 will allow running flake8 tests on a subset of changes (only HEAD) which is quicker. Change-Id: I9069edad75befcd4995a1c23924e2856da56c216 Signed-off-by: Arnaud M --- tools/flake8wrap.sh | 24 ++++++++++++++++++++++++ tox.ini | 6 ++++++ 2 files changed, 30 insertions(+) create mode 100755 tools/flake8wrap.sh diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh new file mode 100755 index 000000000..93771e3aa --- /dev/null +++ b/tools/flake8wrap.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 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 +# or +# tox -efast8 +# + +if test "x$1" = "x-HEAD" ; then + shift + files=$(git diff --name-only HEAD~1 | tr '\n' ' ') + echo "Running flake8 on ${files}" + echo "" + diff -u --from-file /dev/null ${files} | flake8 "$@" +else + echo "Running flake8 on all files" + echo "" + exec flake8 "$@" +fi diff --git a/tox.ini b/tox.ini index a7ff4cc3f..cd33b4e61 100644 --- a/tox.ini +++ b/tox.ini @@ -33,6 +33,12 @@ commands = doc8 doc/source flake8 {posargs} . {toxinidir}/tools/sync_db.py +[testenv:fast8] +description = + Run style checks on the changes made since HEAD~. For a full run including docs, use 'pep8' +commands = + bash tools/flake8wrap.sh -HEAD + # Deprecated [testenv:unit-postgresql] description =