@@ -78,8 +78,9 @@ def format_file(file: Path, check: bool, formatter) -> bool:
7878 check = True ,
7979 )
8080 print (f"{ Fore .CYAN } Formatted: { file } { Style .RESET_ALL } " )
81-
81+ elif formatter == "ruff" :
8282 ruff_cmd = ["ruff" , "check" , file ]
83+ ruff_format_cmd = ["ruff" , "format" , file ]
8384 try :
8485 if check :
8586 process = subprocess .run (
@@ -94,6 +95,22 @@ def format_file(file: Path, check: bool, formatter) -> bool:
9495 f"Use { Fore .CYAN } ruff check --fix { file } { Style .RESET_ALL } to fix it."
9596 )
9697 formatted = False
98+
99+ ruff_format_cmd .insert (2 , "--check" )
100+ process = subprocess .run (
101+ ruff_format_cmd ,
102+ capture_output = True ,
103+ text = True ,
104+ check = False ,
105+ )
106+ if process .returncode != 0 :
107+ print (
108+ f"{ Fore .YELLOW } { file } is not ruff-formatted.{ Style .RESET_ALL } "
109+ )
110+ print (
111+ f"Use { Fore .CYAN } ruff format { file } { Style .RESET_ALL } to format it."
112+ )
113+ formatted = False
97114 else :
98115 ruff_cmd .insert (2 , "--fix" )
99116 process = subprocess .run (
@@ -111,6 +128,24 @@ def format_file(file: Path, check: bool, formatter) -> bool:
111128 formatted = False
112129 else :
113130 print (f"{ Fore .CYAN } Ruff fixed: { file } { Style .RESET_ALL } " )
131+
132+ process = subprocess .run (
133+ ruff_format_cmd ,
134+ capture_output = True ,
135+ text = True ,
136+ check = False ,
137+ )
138+ if process .returncode != 0 :
139+ print (
140+ f"{ Fore .RED } Ruff format failed for { file } .{ Style .RESET_ALL } "
141+ )
142+ if process .stdout :
143+ print (process .stdout , end = "" )
144+ if process .stderr :
145+ print (process .stderr , end = "" )
146+ formatted = False
147+ else :
148+ print (f"{ Fore .CYAN } Ruff formatted: { file } { Style .RESET_ALL } " )
114149 except FileNotFoundError :
115150 print (
116151 f"{ Fore .RED } Formatter ruff not found, { file } skipped.{ Style .RESET_ALL } "
@@ -217,9 +252,7 @@ def main():
217252 parser .add_argument (
218253 "--c" , default = "clang-format-16" , help = "C formatter (default: clang-format-16)"
219254 )
220- parser .add_argument (
221- "--py" , default = "black" , help = "Python formatter (default: black)"
222- )
255+ parser .add_argument ("--py" , default = "ruff" , help = "Python formatter (default: ruff)" )
223256 args = parser .parse_args ()
224257
225258 if args .ref is None and args .path is None :
0 commit comments