@@ -9,81 +9,81 @@ RUFF_UNSAFE_FIXES_FLAG=""
99
1010# Process command-line arguments
1111while [[ " $# " -gt 0 ]]; do
12- case " $1 " in
13- --all)
14- FORMAT_ALL=true
15- echo " Detected --all flag: Formatting all tracked Python files."
16- shift # Consume the argument
17- ;;
18- --unsafe-fixes)
19- RUFF_UNSAFE_FIXES_FLAG=" --unsafe-fixes"
20- echo " Detected --unsafe-fixes flag: Ruff will run with unsafe fixes."
21- shift # Consume the argument
22- ;;
23- * )
24- # Handle unknown arguments or just ignore them
25- echo " Warning: Unknown argument '$1 '. Ignoring."
26- shift # Consume the argument
27- ;;
28- esac
12+ case " $1 " in
13+ --all)
14+ FORMAT_ALL=true
15+ echo " Detected --all flag: Formatting all tracked Python files."
16+ shift # Consume the argument
17+ ;;
18+ --unsafe-fixes)
19+ RUFF_UNSAFE_FIXES_FLAG=" --unsafe-fixes"
20+ echo " Detected --unsafe-fixes flag: Ruff will run with unsafe fixes."
21+ shift # Consume the argument
22+ ;;
23+ * )
24+ # Handle unknown arguments or just ignore them
25+ echo " Warning: Unknown argument '$1 '. Ignoring."
26+ shift # Consume the argument
27+ ;;
28+ esac
2929done
3030
3131# Sort Spelling Allowlist
3232SPELLING_ALLOW_FILE=" .github/actions/spelling/allow.txt"
3333if [ -f " $SPELLING_ALLOW_FILE " ]; then
34- echo " Sorting and de-duplicating $SPELLING_ALLOW_FILE "
35- sort -u " $SPELLING_ALLOW_FILE " -o " $SPELLING_ALLOW_FILE "
34+ echo " Sorting and de-duplicating $SPELLING_ALLOW_FILE "
35+ sort -u " $SPELLING_ALLOW_FILE " -o " $SPELLING_ALLOW_FILE "
3636fi
3737
3838CHANGED_FILES=" "
3939
4040if $FORMAT_ALL ; then
41- echo " Finding all tracked Python files in the repository..."
42- CHANGED_FILES=$( git ls-files -- ' *.py' ' :!src/a2a/grpc/*' )
41+ echo " Finding all tracked Python files in the repository..."
42+ CHANGED_FILES=$( git ls-files -- ' *.py' ' :!src/a2a/grpc/*' )
4343else
44- echo " Finding changed Python files based on git diff..."
45- TARGET_BRANCH=" origin/${GITHUB_BASE_REF:- main} "
46- git fetch origin " ${GITHUB_BASE_REF:- main} " --depth=1
44+ echo " Finding changed Python files based on git diff..."
45+ TARGET_BRANCH=" origin/${GITHUB_BASE_REF:- main} "
46+ git fetch origin " ${GITHUB_BASE_REF:- main} " --depth=1
4747
48- MERGE_BASE=$( git merge-base HEAD " $TARGET_BRANCH " )
48+ MERGE_BASE=$( git merge-base HEAD " $TARGET_BRANCH " )
4949
50- # Get python files changed in this PR, excluding grpc generated files.
51- CHANGED_FILES=$( git diff --name-only --diff-filter=ACMRTUXB " $MERGE_BASE " HEAD -- ' *.py' ' :!src/a2a/grpc/*' )
50+ # Get python files changed in this PR, excluding grpc generated files.
51+ CHANGED_FILES=$( git diff --name-only --diff-filter=ACMRTUXB " $MERGE_BASE " HEAD -- ' *.py' ' :!src/a2a/grpc/*' )
5252fi
5353
5454# Exit if no files were found
5555if [ -z " $CHANGED_FILES " ]; then
56- echo " No changed or tracked Python files to format."
57- exit 0
56+ echo " No changed or tracked Python files to format."
57+ exit 0
5858fi
5959
6060# --- Helper Function ---
6161# Runs a command on a list of files passed via stdin.
6262# $1: A string containing the list of files (space-separated).
6363# $2...: The command and its arguments to run.
6464run_formatter () {
65- local files_to_format=" $1 "
66- shift # Remove the file list from the arguments
67- if [ -n " $files_to_format " ]; then
68- echo " $files_to_format " | xargs -r " $@ "
69- fi
65+ local files_to_format=" $1 "
66+ shift # Remove the file list from the arguments
67+ if [ -n " $files_to_format " ]; then
68+ echo " $files_to_format " | xargs -r " $@ "
69+ fi
7070}
7171
7272# --- Python File Formatting ---
7373if [ -n " $CHANGED_FILES " ]; then
74- echo " --- Formatting Python Files ---"
75- echo " Files to be formatted:"
76- echo " $CHANGED_FILES "
74+ echo " --- Formatting Python Files ---"
75+ echo " Files to be formatted:"
76+ echo " $CHANGED_FILES "
7777
78- echo " Running autoflake..."
79- run_formatter " $CHANGED_FILES " autoflake -i -r --remove-all-unused-imports
80- echo " Running ruff check (fix-only)..."
81- run_formatter " $CHANGED_FILES " ruff check --fix-only $RUFF_UNSAFE_FIXES_FLAG
82- echo " Running ruff format..."
83- run_formatter " $CHANGED_FILES " ruff format
84- echo " Python formatting complete."
78+ echo " Running autoflake..."
79+ run_formatter " $CHANGED_FILES " autoflake -i -r --remove-all-unused-imports
80+ echo " Running ruff check (fix-only)..."
81+ run_formatter " $CHANGED_FILES " ruff check --fix-only $RUFF_UNSAFE_FIXES_FLAG
82+ echo " Running ruff format..."
83+ run_formatter " $CHANGED_FILES " ruff format
84+ echo " Python formatting complete."
8585else
86- echo " No Python files to format."
86+ echo " No Python files to format."
8787fi
8888
8989echo " All formatting tasks are complete."
0 commit comments