|
38 | 38 | N_TESTS_TO_GENERATE, |
39 | 39 | TOTAL_LOOPING_TIME, |
40 | 40 | ) |
41 | | -from codeflash.code_utils.formatter import format_code, sort_imports |
| 41 | +from codeflash.code_utils.formatter import format_code, sort_imports_in_place |
42 | 42 | from codeflash.code_utils.instrument_existing_tests import inject_profiling_into_existing_test |
43 | 43 | from codeflash.code_utils.line_profile_utils import add_decorator_imports |
44 | 44 | from codeflash.code_utils.remove_generated_tests import remove_functions_from_generated_tests |
@@ -305,20 +305,8 @@ def optimize_function(self) -> Result[BestOptimization, str]: |
305 | 305 | ) |
306 | 306 |
|
307 | 307 | if not self.args.disable_imports_sorting: |
308 | | - main_file_path = self.function_to_optimize.file_path |
309 | | - if main_file_path.exists(): |
310 | | - current_main_content = main_file_path.read_text(encoding="utf8") |
311 | | - sorted_main_content = sort_imports(current_main_content) |
312 | | - if sorted_main_content != current_main_content: |
313 | | - main_file_path.write_text(sorted_main_content, encoding="utf8") |
314 | | - |
315 | | - writable_helper_file_paths = {hf.file_path for hf in code_context.helper_functions} |
316 | | - for helper_file_path in writable_helper_file_paths: |
317 | | - if helper_file_path.exists(): |
318 | | - current_helper_content = helper_file_path.read_text(encoding="utf8") |
319 | | - sorted_helper_content = sort_imports(current_helper_content) |
320 | | - if sorted_helper_content != current_helper_content: |
321 | | - helper_file_path.write_text(sorted_helper_content, encoding="utf8") |
| 308 | + path_to_sort_imports_for = [self.function_to_optimize.file_path] + [hf.file_path for hf in code_context.helper_functions] |
| 309 | + sort_imports_in_place(path_to_sort_imports_for) |
322 | 310 |
|
323 | 311 | new_code = self.function_to_optimize.file_path.read_text(encoding="utf8") |
324 | 312 | new_helper_code: dict[Path, str] = {} |
|
0 commit comments