@@ -112,48 +112,40 @@ 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-
123- # Color the output if it goes to a terminal or GitHub Actions log.
124- arg_color=()
125- if [[ -t 1 || " ${CI} " == true ]]; then
126- arg_color=(" --color" )
127- fi
128-
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" )
115+ # Run ruff for import sorting.
116+ # We do this first so that if it changes files, the formatting step will pick them up.
117+ echo " Running ruff check (isort)..."
118+ check_args=(" check" " --select" " I" " ${arg_color[@]} " )
119+ if (( only_print == 0 )) ; then
120+ check_args+=(" --fix" )
121+ else
122+ # In check mode, we want to see diffs if possible, but ruff check usually just prints violations.
123+ # To match previous behavior of "checking" without modifying, we don't add --fix.
124+ # If we want diffs for imports, --diff can be used.
125+ check_args+=(" --diff" )
136126fi
137127
138- ISORTSTATUS=0
139- if (( "${# isort_files[@]} " )) ; then
140- isort " ${args[@]} " " ${isort_files[@]} "
141- ISORTSTATUS=$?
128+ RUFF_CHECK_STATUS=0
129+ if (( "${# format_files[@]} " )) ; then
130+ # We pass all files to ruff; it handles excluding those that shouldn't be touched if configured,
131+ # but here we are passing a specific list of files.
132+ ruff " ${check_args[@]} " " ${format_files[@]} "
133+ RUFF_CHECK_STATUS=$?
142134fi
143135
144- BLACKVERSION=$( black --version | head -1)
145-
146- echo " Running the black formatter... (version: $BLACKVERSION )"
147-
148- args=(" ${arg_color[@]} " )
136+ echo " Running ruff format..."
137+ format_args=(" format" " ${arg_color[@]} " )
149138if (( only_print == 1 )) ; then
150- args +=(" --check" " --diff" )
139+ format_args +=(" --check" " --diff" )
151140fi
152141
153- black " ${args[@]} " " ${format_files[@]} "
154- BLACKSTATUS=$?
142+ RUFF_FORMAT_STATUS=0
143+ if (( "${# format_files[@]} " )) ; then
144+ ruff " ${format_args[@]} " " ${format_files[@]} "
145+ RUFF_FORMAT_STATUS=$?
146+ fi
155147
156- if (( BLACKSTATUS || ISORTSTATUS )) ; then
148+ if (( RUFF_CHECK_STATUS || RUFF_FORMAT_STATUS )) ; then
157149 exit 1
158150fi
159151exit 0
0 commit comments