From c1d0e3c60e608848f074238c199ce04950d2b355 Mon Sep 17 00:00:00 2001 From: Jerome Berthier Date: Wed, 19 Aug 2020 18:09:46 +0200 Subject: [PATCH] tools/pyflakes.sh: allow to override PYFILES from environment variable Useful when using with a pre-push hook, it is useless to run flakes on the whole code base every time you push. Example of pre-push hook using this feature: ref=$(git rev-list --boundary HEAD...master | grep "^-" | cut -c2-) PYFILES="$(git diff ${ref} --name-only | grep -E "*.py$" | xargs)" $PWD/tools/pyflakes.sh if [ "$?" -ne "0" ]; then echo >&2 "Flakes error" exit 1 fi --- tools/pyflakes.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/pyflakes.sh b/tools/pyflakes.sh index 860f9f740f..aadf2440da 100755 --- a/tools/pyflakes.sh +++ b/tools/pyflakes.sh @@ -7,8 +7,13 @@ cd $(dirname $0)/.. MODULE_FILES=$(git ls-files modules|grep '\.py$') -PYFILES=$(git ls-files | grep '^scripts\|\.py$'|grep -v boilerplate_data|grep -v stable_backport_data|grep -v '^modules'|grep -v '^contrib') -PYFILES="$PYFILES $MODULE_FILES" +# Takes PYFILES from env, if empty use all git tracked files +: ${PYFILES:=} +if [ -z "${PYFILES}" ]; then + PYFILES="$(git ls-files | grep '^scripts\|\.py$'|grep -v boilerplate_data|grep -v stable_backport_data|grep -v '^modules'|grep -v '^contrib')" + PYFILES="$PYFILES $MODULE_FILES" +fi + grep -n '[[:space:]]$' ${PYFILES} && echo 'Error: tabs or trailing whitespace found, remove them' && err=4 grep -Fn '.setlocale' ${PYFILES} && echo 'Error: do not use setlocale' && err=5 grep -Fn '__future__ import with_statement' ${PYFILES} && echo 'Error: with_statement useless as we do not support Python 2.5' && err=6 -- GitLab