Skip to content

Commit 21e8fe8

Browse files
Merge pull request #375 from codeflash-ai/cleanup-properly
cleanup properly
2 parents 859d50b + dd622c6 commit 21e8fe8

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

codeflash/cli_cmds/cmd_init.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,8 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test
941941
command = ["codeflash", "--file", "bubble_sort.py", "--function", "sorter"]
942942
if args.no_pr:
943943
command.append("--no-pr")
944+
if args.verbose:
945+
command.append("--verbose")
944946

945947
logger.info("Running sample optimization…")
946948
console.rule()
@@ -953,7 +955,7 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test
953955
if process.stdout:
954956
for line in process.stdout:
955957
stripped = line.strip()
956-
console.print(stripped)
958+
console.out(stripped)
957959
output.append(stripped)
958960
process.wait()
959961
console.rule()

codeflash/optimization/function_optimizer.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,23 +1321,11 @@ def generate_and_instrument_tests(
13211321
]
13221322

13231323
def cleanup_generated_files(self) -> None:
1324-
paths_to_cleanup = (
1325-
[
1326-
test_file.instrumented_behavior_file_path
1327-
for test_type in [
1328-
TestType.GENERATED_REGRESSION,
1329-
TestType.EXISTING_UNIT_TEST,
1330-
TestType.CONCOLIC_COVERAGE_TEST,
1331-
]
1332-
for test_file in self.test_files.get_by_type(test_type).test_files
1333-
]
1334-
+ [
1335-
test_file.benchmarking_file_path
1336-
for test_type in [TestType.GENERATED_REGRESSION, TestType.EXISTING_UNIT_TEST]
1337-
for test_file in self.test_files.get_by_type(test_type).test_files
1338-
]
1339-
+ [self.test_cfg.concolic_test_root_dir]
1340-
)
1324+
paths_to_cleanup = [self.test_cfg.concolic_test_root_dir]
1325+
for test_file in self.test_files:
1326+
paths_to_cleanup.append(test_file.instrumented_behavior_file_path)
1327+
paths_to_cleanup.append(test_file.benchmarking_file_path)
1328+
13411329
cleanup_paths(paths_to_cleanup)
13421330
if hasattr(get_run_tmp_file, "tmpdir"):
13431331
get_run_tmp_file.tmpdir.cleanup()

codeflash/optimization/optimizer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(self, args: Namespace) -> None:
4545
self.local_aiservice_client = LocalAiServiceClient() if self.experiment_id else None
4646
self.replay_tests_dir = None
4747
self.functions_checkpoint: CodeflashRunCheckpoint | None = None
48+
self.current_function_optimizer: FunctionOptimizer | None = None
4849

4950
def create_function_optimizer(
5051
self,
@@ -265,7 +266,9 @@ def run(self) -> None:
265266
function_to_tests,
266267
validated_original_code[original_module_path].source_code,
267268
)
268-
269+
self.current_function_optimizer = (
270+
function_optimizer # needed to clean up from the outside of this function
271+
)
269272
best_optimization = function_optimizer.optimize_function()
270273
if self.functions_checkpoint:
271274
self.functions_checkpoint.add_function_to_checkpoint(
@@ -293,6 +296,9 @@ def run(self) -> None:
293296
def cleanup_temporary_paths(self) -> None:
294297
from codeflash.code_utils.code_utils import cleanup_paths
295298

299+
if self.current_function_optimizer:
300+
self.current_function_optimizer.cleanup_generated_files()
301+
296302
cleanup_paths([self.test_cfg.concolic_test_root_dir, self.replay_tests_dir])
297303

298304

codeflash/telemetry/sentry.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: #
1212
if exclude_errors
1313
else logging.ERROR, # Otherwise, error logs will create sentry events
1414
)
15+
1516
sentry_sdk.init(
1617
dsn="https://4b9a1902f9361b48c04376df6483bc96@o4506833230561280.ingest.sentry.io/4506833262477312",
1718
integrations=[sentry_logging],
@@ -22,4 +23,5 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: #
2223
# of sampled transactions.
2324
# We recommend adjusting this value in production.
2425
profiles_sample_rate=1.0,
26+
ignore_errors=[KeyboardInterrupt],
2527
)

0 commit comments

Comments
 (0)