Skip to content

Commit 6d475c4

Browse files
committed
Enhance CI formatting checks for Python files
- Update `.ci/check-format.sh` to include checks for Python files using Black. - Modify `.github/workflows/main.yml` to install Python dependencies for formatting. - Add Python-specific settings to `.editorconfig` to enforce consistent formatting rules. This ensures that both shell scripts and Python files adhere to defined coding standards.
1 parent 88ddb73 commit 6d475c4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.ci/check-format.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,15 @@ for file in ${SH_SOURCES}; do
2121
done
2222
SH_MISMATCH_FILE_CNT=$(shfmt -l ${SH_SOURCES})
2323

24-
exit $((C_MISMATCH_LINE_CNT + SH_MISMATCH_FILE_CNT))
24+
PY_SOURCES=$(find "${REPO_ROOT}" | egrep "\.py$")
25+
for file in ${PY_SOURCES}; do
26+
echo "Checking Python file: ${file}"
27+
black --diff "${file}"
28+
done
29+
PY_MISMATCH_FILE_CNT=0
30+
if [ -n "${PY_SOURCES}" ]; then
31+
PY_MISMATCH_OUTPUT=$(black --check ${PY_SOURCES} 2>&1)
32+
PY_MISMATCH_FILE_CNT=$(echo "${PY_MISMATCH_OUTPUT}" | grep -c "^would reformat ")
33+
fi
34+
35+
exit $((C_MISMATCH_LINE_CNT + SH_MISMATCH_FILE_CNT + PY_MISMATCH_FILE_CNT))

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,13 @@ function_next_line = true
1212
switch_case_indent = true
1313
space_redirects = true
1414
binary_next_line = true
15+
16+
17+
# Python-specific settings
18+
[*.py]
19+
indent_style = space
20+
indent_size = 4
21+
end_of_line = lf
22+
trim_trailing_whitespace = true
23+
insert_final_newline = true
24+
max_line_length = 88

.github/workflows/main.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ jobs:
505505
- uses: actions/checkout@v4
506506
- name: coding convention
507507
run: |
508-
sudo apt-get install -q=2 clang-format-18 shfmt
508+
sudo apt-get install -q=2 clang-format-18 shfmt python3-pip
509+
pip3 install black
509510
.ci/check-newline.sh
510511
.ci/check-format.sh
511512
shell: bash

0 commit comments

Comments
 (0)