Skip to content

Commit 65eb6ee

Browse files
committed
cleanup paths in optimizer.py
1 parent bfe9bb5 commit 65eb6ee

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,7 @@ def optimize_function(self) -> Result[BestOptimization, str]:
319319
original_helper_code,
320320
self.function_to_optimize.file_path,
321321
)
322-
323-
# lista filepath
324-
filespaths = generated_test_paths + generated_perf_test_paths
325-
# remove all test files
326-
cleanup_paths(filespaths)
322+
cleanup_paths(generated_test_paths + generated_perf_test_paths)
327323

328324

329325
if not best_optimization:

codeflash/optimization/optimizer.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from codeflash.optimization.function_optimizer import FunctionOptimizer
2121
from codeflash.telemetry.posthog_cf import ph
2222
from codeflash.verification.verification_utils import TestConfig
23+
from codeflash.code_utils.code_utils import cleanup_paths
2324

2425
if TYPE_CHECKING:
2526
from argparse import Namespace
@@ -177,16 +178,22 @@ def run(self) -> None:
177178
logger.info("✨ All functions have been optimized! ✨")
178179
finally:
179180
if function_optimizer:
180-
for test_file in function_optimizer.test_files.get_by_type(TestType.GENERATED_REGRESSION).test_files:
181-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
182-
test_file.benchmarking_file_path.unlink(missing_ok=True)
183-
for test_file in function_optimizer.test_files.get_by_type(TestType.EXISTING_UNIT_TEST).test_files:
184-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
185-
test_file.benchmarking_file_path.unlink(missing_ok=True)
186-
for test_file in function_optimizer.test_files.get_by_type(TestType.CONCOLIC_COVERAGE_TEST).test_files:
187-
test_file.instrumented_behavior_file_path.unlink(missing_ok=True)
188-
if function_optimizer.test_cfg.concolic_test_root_dir:
189-
shutil.rmtree(function_optimizer.test_cfg.concolic_test_root_dir, ignore_errors=True)
181+
list_of_paths_to_delete = [
182+
test_file.instrumented_behavior_file_path
183+
for test_type in [
184+
TestType.GENERATED_REGRESSION,
185+
TestType.EXISTING_UNIT_TEST,
186+
TestType.CONCOLIC_COVERAGE_TEST,
187+
]
188+
for test_file in function_optimizer.test_files.get_by_type(test_type).test_files
189+
] + [
190+
test_file.benchmarking_file_path
191+
for test_type in [TestType.GENERATED_REGRESSION, TestType.EXISTING_UNIT_TEST]
192+
for test_file in function_optimizer.test_files.get_by_type(test_type).test_files
193+
] + [function_optimizer.test_cfg.concolic_test_root_dir]
194+
195+
cleanup_paths(list_of_paths_to_delete)
196+
190197
if hasattr(get_run_tmp_file, "tmpdir"):
191198
get_run_tmp_file.tmpdir.cleanup()
192199

0 commit comments

Comments
 (0)