|
62 | 62 | from codeflash.models.models import ( |
63 | 63 | BestOptimization, |
64 | 64 | CodeOptimizationContext, |
| 65 | + CodeStringsMarkdown, |
65 | 66 | GeneratedTests, |
66 | 67 | GeneratedTestsList, |
67 | 68 | OptimizationSet, |
|
93 | 94 | from codeflash.either import Result |
94 | 95 | from codeflash.models.models import ( |
95 | 96 | BenchmarkKey, |
96 | | - CodeStringsMarkdown, |
97 | 97 | CoverageData, |
98 | 98 | FunctionCalledInTest, |
99 | 99 | FunctionSource, |
@@ -621,13 +621,18 @@ def replace_function_and_helpers_with_optimized_code( |
621 | 621 | read_writable_functions_by_file_path[self.function_to_optimize.file_path].add( |
622 | 622 | self.function_to_optimize.qualified_name |
623 | 623 | ) |
| 624 | + code_strings = CodeStringsMarkdown.from_str_with_markers(optimized_code) |
| 625 | + optimized_code_dict = {code_string.file_path: code_string.code for code_string in code_strings} |
| 626 | + logger.debug(f"Optimized code: {optimized_code_dict}") |
624 | 627 | for helper_function in code_context.helper_functions: |
625 | 628 | if helper_function.jedi_definition.type != "class": |
626 | 629 | read_writable_functions_by_file_path[helper_function.file_path].add(helper_function.qualified_name) |
627 | 630 | for module_abspath, qualified_names in read_writable_functions_by_file_path.items(): |
| 631 | + relative_module_path = module_abspath.relative_to(self.project_root) |
| 632 | + logger.debug(f"applying optimized code to: {relative_module_path}") |
628 | 633 | did_update |= replace_function_definitions_in_module( |
629 | 634 | function_names=list(qualified_names), |
630 | | - optimized_code=optimized_code, |
| 635 | + optimized_code=optimized_code_dict.get(relative_module_path), |
631 | 636 | module_abspath=module_abspath, |
632 | 637 | preexisting_objects=code_context.preexisting_objects, |
633 | 638 | project_root_path=self.project_root, |
|
0 commit comments