diff --git a/utils/cq/requirements.txt b/utils/cq/requirements.txt index 0a75415b687..20f5c5ba003 100644 --- a/utils/cq/requirements.txt +++ b/utils/cq/requirements.txt @@ -2,7 +2,7 @@ pyenchant ## flake8 6 removed --diff option which breaks flake precommit hook. ## https://github.com/pycqa/flake8/issues/1389 https://github.com/PyCQA/flake8/pull/1720 -flake8<6.0.0 +flake8==7.1.1 isort==5.13.2 pylint==3.3.2 yamllint==1.35.1 diff --git a/utils/githooks/pre-commit.d/71-flake.sh b/utils/githooks/pre-commit.d/71-flake.sh index 2a7614a876b..a41f28af5c2 100755 --- a/utils/githooks/pre-commit.d/71-flake.sh +++ b/utils/githooks/pre-commit.d/71-flake.sh @@ -20,19 +20,17 @@ set -ue _print_githook_header "Flake8" -if ! command -v flake8 > /dev/null 2>&1; then - echo "flake8 not installed. Install flake8 command to improve pre-commit checks:" - echo " python3 -m pip install -r ./utils/cq/requirements.txt" - exit 0 -fi -if flake8 --version | grep ^6\\.; then - echo "flake8 >= 6.x does not have the --diff option. Skipping." +py_files=$(_git_diff_cached_files "*.py SConstruct */SConscript") + +if [ -z "$py_files" ]; then + echo "No python changes. Skipping" exit 0 fi -if [ ! -f .flake8 ]; then - echo "No .flake8 config. Skipping" +if ! command -v flake8 > /dev/null 2>&1; then + echo "flake8 not installed. Install flake8 command to improve pre-commit checks:" + echo " python3 -m pip install -r ./utils/cq/requirements.txt" exit 0 fi @@ -47,12 +45,17 @@ if [ "$BRANCH" = "origin/master" ]; then echo " Checking tree" flake8 --statistics else - - # shellcheck disable=SC1091 + rc=0 # non-scons - git diff "$TARGET" -U10 | flake8 --config .flake8 --diff + if ! echo "$py_files" | grep -vi scons | xargs flake8 --config .flake8; then + rc=1 + fi # scons - git diff "$TARGET" -U10 | flake8 --config .flake8-scons --diff + if ! echo "$py_files" | grep -i scons | xargs flake8 --config .flake8-scons; then + rc=1; + fi + + exit "$rc" fi