|
12 | 12 | from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
|
13 | 13 | from codeflash.cli_cmds.console import console, logger, progress_bar
|
14 | 14 | from codeflash.code_utils import env_utils
|
| 15 | +from codeflash.code_utils.code_utils import cleanup_paths |
15 | 16 | from codeflash.code_utils.env_utils import get_pr_number
|
16 | 17 | from codeflash.either import is_successful
|
17 | 18 | from codeflash.models.models import ValidCode
|
@@ -248,10 +249,10 @@ def run(self) -> None:
|
248 | 249 | return
|
249 | 250 | if not env_utils.check_formatter_installed(self.args.formatter_cmds):
|
250 | 251 | return
|
251 |
| - |
252 | 252 | if self.args.no_draft and is_pr_draft():
|
253 | 253 | logger.warning("PR is in draft mode, skipping optimization")
|
254 | 254 | return
|
| 255 | + cleanup_paths(Optimizer.find_leftover_instrumented_test_files(self.test_cfg.tests_root)) |
255 | 256 |
|
256 | 257 | function_optimizer = None
|
257 | 258 | file_to_funcs_to_optimize, num_optimizable_functions = self.get_optimizable_functions()
|
@@ -326,9 +327,27 @@ def run(self) -> None:
|
326 | 327 |
|
327 | 328 | self.cleanup_temporary_paths()
|
328 | 329 |
|
329 |
| - def cleanup_temporary_paths(self) -> None: |
330 |
| - from codeflash.code_utils.code_utils import cleanup_paths |
| 330 | + @staticmethod |
| 331 | + def find_leftover_instrumented_test_files(test_root: Path) -> list[Path]: |
| 332 | + """Search for all paths within the test_root that match the following patterns. |
331 | 333 |
|
| 334 | + - 'test.*__perf_test_{0,1}.py' |
| 335 | + - 'test_.*__unit_test_{0,1}.py' |
| 336 | + - 'test_.*__perfinstrumented.py' |
| 337 | + - 'test_.*__perfonlyinstrumented.py' |
| 338 | + Returns a list of matching file paths. |
| 339 | + """ |
| 340 | + import re |
| 341 | + |
| 342 | + pattern = re.compile( |
| 343 | + r"(?:test.*__perf_test_\d?\.py|test_.*__unit_test_\d?\.py|test_.*__perfinstrumented\.py|test_.*__perfonlyinstrumented\.py)$" |
| 344 | + ) |
| 345 | + |
| 346 | + return [ |
| 347 | + file_path for file_path in test_root.rglob("*") if file_path.is_file() and pattern.match(file_path.name) |
| 348 | + ] |
| 349 | + |
| 350 | + def cleanup_temporary_paths(self) -> None: |
332 | 351 | if self.current_function_optimizer:
|
333 | 352 | self.current_function_optimizer.cleanup_generated_files()
|
334 | 353 |
|
|
0 commit comments