Skip to content

Commit

Permalink
DAOS-16865 cq: update flake8 to 7.1.1
Browse files Browse the repository at this point in the history
Update flake8 to 7.1.1.
Adjust githook to work with newer flake8.
Also tested to be backwards compatible with flake8<6

Skip-build: true

Required-githooks: true

Signed-off-by: Dalton Bohning <[email protected]>
  • Loading branch information
daltonbohning committed Dec 9, 2024
1 parent ab5815d commit 6a16cd2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion utils/cq/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 16 additions & 13 deletions utils/githooks/pre-commit.d/71-flake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit 6a16cd2

Please sign in to comment.