@@ -112,48 +112,46 @@ 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
126118 arg_color=(" --color" )
127119fi
128120
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" )
121+ # Run ruff for import sorting.
122+ # We do this first so that if it changes files, the formatting step will pick them up.
123+ echo " Running ruff check (isort)..."
124+ check_args=(" check" " --select" " I" " ${arg_color[@]} " )
125+ if (( only_print == 0 )) ; then
126+ check_args+=(" --fix" )
127+ else
128+ # In check mode, we want to see diffs if possible, but ruff check usually just prints violations.
129+ # To match previous behavior of "checking" without modifying, we don't add --fix.
130+ # If we want diffs for imports, --diff can be used.
131+ check_args+=(" --diff" )
136132fi
137133
138- ISORTSTATUS=0
139- if (( "${# isort_files[@]} " )) ; then
140- isort " ${args[@]} " " ${isort_files[@]} "
141- ISORTSTATUS=$?
134+ RUFF_CHECK_STATUS=0
135+ if (( "${# format_files[@]} " )) ; then
136+ # We pass all files to ruff; it handles excluding those that shouldn't be touched if configured,
137+ # but here we are passing a specific list of files.
138+ ruff " ${check_args[@]} " " ${format_files[@]} "
139+ RUFF_CHECK_STATUS=$?
142140fi
143141
144- BLACKVERSION=$( black --version | head -1)
145-
146- echo " Running the black formatter... (version: $BLACKVERSION )"
147-
148- args=(" ${arg_color[@]} " )
142+ echo " Running ruff format..."
143+ format_args=(" format" " ${arg_color[@]} " )
149144if (( only_print == 1 )) ; then
150- args +=(" --check" " --diff" )
145+ format_args +=(" --check" " --diff" )
151146fi
152147
153- black " ${args[@]} " " ${format_files[@]} "
154- BLACKSTATUS=$?
148+ RUFF_FORMAT_STATUS=0
149+ if (( "${# format_files[@]} " )) ; then
150+ ruff " ${format_args[@]} " " ${format_files[@]} "
151+ RUFF_FORMAT_STATUS=$?
152+ fi
155153
156- if (( BLACKSTATUS || ISORTSTATUS )) ; then
154+ if (( RUFF_CHECK_STATUS || RUFF_FORMAT_STATUS )) ; then
157155 exit 1
158156fi
159157exit 0
0 commit comments