Add isort to the style checking for python

This commit is contained in:
Mikhail f. Shiryaev 2024-09-26 21:12:47 +02:00
parent c4cc1576eb
commit d396ec3310
No known key found for this signature in database
GPG Key ID: 4B02ED204C7D93F4
4 changed files with 44 additions and 1 deletions

View File

@ -30,7 +30,7 @@ disable = '''
[tool.isort]
profile = "black"
src_paths = ["src", "tests/ci", "tests/sqllogic"]
src_paths = ["src", "tests/ci", "tests/sqllogic", "tests/queries", "tests/integration"]
[tool.black]
required-version = 24

36
utils/check-style/check-isort Executable file
View File

@ -0,0 +1,36 @@
#!/usr/bin/env bash
set -e
# We check only our code, that's why we skip contrib
GIT_ROOT=$(git rev-parse --show-cdup)
GIT_ROOT=${GIT_ROOT:-./}
tmp=$(mktemp)
# Find all *.py, *.python files and executable files without extension
# that are determined as python scripts by 'file' util
# in the repo except the contrib directory.
find_cmd=(
find "$GIT_ROOT" -type f -not -path "${GIT_ROOT}contrib/*"
\(
\(
-name '*.py' -or -name "*.python" -or
\(
-executable -not -name "*.*" -exec sh -c 'file {} | grep -q "Python script"' \;
\)
\)
# We skip modules generated by the protocol buffer compiler from *.proto files.
-and -not -name '*_pb2.py' -and -not -name '*_pb2_grpc.py'
\)
)
if ! "${find_cmd[@]}" -exec isort --check --diff {} + 1>"$tmp" 2>&1; then
# Show the result only if some files need formatting
cat "$tmp"
# Apply formatting
"${find_cmd[@]}" -exec isort {} + 1>/dev/null 2>&1
# Automatically add changed files to stage
"${find_cmd[@]}" -exec git add -u {} + 1>/dev/null 2>&1
fi
rm "$tmp"

View File

@ -10,6 +10,12 @@ echo "Check " | ts
runtime=$((`date +%s`-start))
echo "Check python formatting with black. Done. $runtime seconds."
start=`date +%s`
echo "Check " | ts
./check-isort -n |& tee /test_output/isort_output.txt
runtime=$((`date +%s`-start))
echo "Check python formatting with isort. Done. $runtime seconds."
start=`date +%s`
./check-pylint -n |& tee /test_output/pylint_output.txt
runtime=$((`date +%s`-start))

View File

@ -17,6 +17,7 @@ def process_result(result_folder):
"shellcheck",
"style",
"pylint",
"isort",
"black",
"flake8",
"mypy",