@@ -112,48 +112,49 @@ if (( ${#format_files[@]} == 0 )); then
112112 exit 0
113113fi
114114
115- # Apply isort only on Python files with the exception of __init__.py files.
116- declare -a isort_files=()
117- for f in " ${format_files[@]} " ; do
118- if [[ " ${f} " == * .py && " ${f##*/ } " != __init__.py ]]; then
119- isort_files+=(" ${f} " )
120- fi
121- done
122-
123115# Color the output if it goes to a terminal or GitHub Actions log.
124116arg_color=()
125117if [[ -t 1 || " ${CI} " == true ]]; then
126- arg_color=(" --color" )
118+ # Check if ruff supports --color (it might be missing in older/some versions).
119+ if ruff --help 2>&1 | grep -q -- ' --color' ; then
120+ arg_color=(" --color" " always" )
121+ fi
127122fi
128123
129- ISORTVERSION=$( isort --version-number)
130-
131- echo " Sorting imports with isort... (version: $ISORTVERSION )"
132-
133- args=(" ${arg_color[@]} " )
134- if (( only_print == 1 )) ; then
135- args+=(" --check" " --diff" )
124+ # Run ruff for import sorting.
125+ # We do this first so that if it changes files, the formatting step will pick them up.
126+ echo " Running ruff check (isort)..."
127+ check_args=(" check" " --select" " I" " ${arg_color[@]} " )
128+ if (( only_print == 0 )) ; then
129+ check_args+=(" --fix" )
130+ else
131+ # In check mode, we want to see diffs if possible, but ruff check usually just prints violations.
132+ # To match previous behavior of "checking" without modifying, we don't add --fix.
133+ # If we want diffs for imports, --diff can be used.
134+ check_args+=(" --diff" )
136135fi
137136
138- ISORTSTATUS=0
139- if (( "${# isort_files[@]} " )) ; then
140- isort " ${args[@]} " " ${isort_files[@]} "
141- ISORTSTATUS=$?
137+ RUFF_CHECK_STATUS=0
138+ if (( "${# format_files[@]} " )) ; then
139+ # We pass all files to ruff; it handles excluding those that shouldn't be touched if configured,
140+ # but here we are passing a specific list of files.
141+ ruff " ${check_args[@]} " " ${format_files[@]} "
142+ RUFF_CHECK_STATUS=$?
142143fi
143144
144- BLACKVERSION=$( black --version | head -1)
145-
146- echo " Running the black formatter... (version: $BLACKVERSION )"
147-
148- args=(" ${arg_color[@]} " )
145+ echo " Running ruff format..."
146+ format_args=(" format" " ${arg_color[@]} " )
149147if (( only_print == 1 )) ; then
150- args +=(" --check" " --diff" )
148+ format_args +=(" --check" " --diff" )
151149fi
152150
153- black " ${args[@]} " " ${format_files[@]} "
154- BLACKSTATUS=$?
151+ RUFF_FORMAT_STATUS=0
152+ if (( "${# format_files[@]} " )) ; then
153+ ruff " ${format_args[@]} " " ${format_files[@]} "
154+ RUFF_FORMAT_STATUS=$?
155+ fi
155156
156- if (( BLACKSTATUS || ISORTSTATUS )) ; then
157+ if (( RUFF_CHECK_STATUS || RUFF_FORMAT_STATUS )) ; then
157158 exit 1
158159fi
159160exit 0
0 commit comments