@@ -14,16 +14,47 @@ jobs:
1414 PR_FILES_AM : ${{ steps.files.outputs.added_modified }}
1515 PR_FILES_RENAMED : ${{ steps.files.outputs.renamed }}
1616 run : |
17+ # If different modules use different Black configs,
18+ # we need to run Black for each python component group separately.
19+ # Otherwise, they all will use the same config.
20+ ENABLED_DIRS=("cvat-sdk" "cvat-cli" "tests/python/sdk" "tests/python/cli")
21+
22+ isValueIn () {
23+ # Checks if a value is in an array
24+ # https://stackoverflow.com/a/8574392
25+ # args: value, array
26+ local e match="$1"
27+ shift
28+ for e; do
29+ [[ "$e" == "$match" ]] && return 0;
30+ done
31+ return 1
32+ }
33+
34+ startswith () {
35+ # Inspired by https://stackoverflow.com/a/2172367
36+ # Checks if the first arg starts with the second one
37+ local value="$1"
38+ local beginning="$2"
39+ return $([[ $value == ${beginning}* ]])
40+ }
41+
1742 PR_FILES="$PR_FILES_AM $PR_FILES_RENAMED"
43+ UPDATED_DIRS=""
1844 for FILE in $PR_FILES; do
1945 EXTENSION="${FILE##*.}"
20- DIRECTORY="${FILE%%/*}"
21- if [[ "$EXTENSION" == "py" && "$DIRECTORY" == "cvat-cli" ]]; then
22- CHANGED_FILES+=" $FILE"
46+ DIRECTORY="$(dirname $FILE)"
47+ if [[ "$EXTENSION" == "py" ]]; then
48+ for EDIR in ${ENABLED_DIRS[@]}; do
49+ if startswith "${DIRECTORY}/" "${EDIR}/" && ! isValueIn "${EDIR}" ${UPDATED_DIRS[@]};
50+ then
51+ UPDATED_DIRS+=" ${EDIR}"
52+ fi
53+ done
2354 fi
2455 done
2556
26- if [[ ! -z $CHANGED_FILES ]]; then
57+ if [[ ! -z $UPDATED_DIRS ]]; then
2758 sudo apt-get --no-install-recommends install -y build-essential curl python3-dev python3-pip python3-venv
2859 python3 -m venv .env
2960 . .env/bin/activate
3263 mkdir -p black_report
3364
3465 echo "Black version: "$(black --version)
35- echo "The files will be checked: "$(echo $CHANGED_FILES)
36- black --check --config ./cvat-cli/pyproject.toml $CHANGED_FILES > ./black_report/black_checks.txt || EXIT_CODE=$(echo $?) || true
66+ echo "The dirs will be checked: $UPDATED_DIRS"
67+ EXIT_CODE=0
68+ for DIR in $UPDATED_DIRS; do
69+ black --check $DIR >> ./black_report/black_checks.txt || EXIT_CODE=$(($? | $EXIT_CODE)) || true
70+ done
3771 deactivate
3872 exit $EXIT_CODE
3973 else
0 commit comments