@@ -85,6 +85,9 @@ def apply_formatter_cmds(
8585 expand = False ,
8686 )
8787 console .print (panel )
88+ logger .warning (
89+ f"Formatter command not found: { ' ' .join (formatter_cmd_list )} , continuing without formatting"
90+ )
8891 if exit_on_failure :
8992 raise e from None
9093
@@ -126,28 +129,41 @@ def format_code(
126129 original_temp = Path (test_dir_str ) / "original_temp.py"
127130 original_temp .write_text (original_code_without_opfunc , encoding = "utf8" )
128131
129- formatted_temp , formatted_code = apply_formatter_cmds (
130- formatter_cmds , original_temp , test_dir_str , print_status = False
131- )
132+ try :
133+ formatted_temp , formatted_code = apply_formatter_cmds (
134+ formatter_cmds , original_temp , test_dir_str , print_status = False
135+ )
132136
133- diff_output = generate_unified_diff (
134- original_code_without_opfunc , formatted_code , from_file = str (original_temp ), to_file = str (formatted_temp )
135- )
136- diff_lines_count = get_diff_lines_count (diff_output )
137+ diff_output = generate_unified_diff (
138+ original_code_without_opfunc ,
139+ formatted_code ,
140+ from_file = str (original_temp ),
141+ to_file = str (formatted_temp ),
142+ )
143+ diff_lines_count = get_diff_lines_count (diff_output )
137144
138- max_diff_lines = min (int (original_code_lines * 0.3 ), 50 )
145+ max_diff_lines = min (int (original_code_lines * 0.3 ), 50 )
139146
140- if diff_lines_count > max_diff_lines and max_diff_lines != - 1 :
141- logger .debug (
142- f"Skipping formatting { path } : { diff_lines_count } lines would change (max: { max_diff_lines } )"
143- )
147+ if diff_lines_count > max_diff_lines and max_diff_lines != - 1 :
148+ logger .debug (
149+ f"Skipping formatting { path } : { diff_lines_count } lines would change (max: { max_diff_lines } )"
150+ )
151+ except FileNotFoundError as e :
152+ logger .warning (f"Formatter not found, skipping diff check: { e } " )
153+ # Continue without formatting checks
144154 return original_code
155+
145156 # TODO : We can avoid formatting the whole file again and only formatting the optimized code standalone and replace in formatted file above.
146- _ , formatted_code = apply_formatter_cmds (
147- formatter_cmds , path , test_dir_str = None , print_status = print_status , exit_on_failure = exit_on_failure
148- )
149- logger .debug (f"Formatted { path } with commands: { formatter_cmds } " )
150- return formatted_code
157+ try :
158+ _ , formatted_code = apply_formatter_cmds (
159+ formatter_cmds , path , test_dir_str = None , print_status = print_status , exit_on_failure = exit_on_failure
160+ )
161+ except FileNotFoundError as e :
162+ logger .warning (f"Formatter not found, returning original code: { e } " )
163+ return original_code
164+ else :
165+ logger .debug (f"Formatted { path } with commands: { formatter_cmds } " )
166+ return formatted_code
151167
152168
153169def sort_imports (code : str ) -> str :
0 commit comments