Skip to content

Commit 1aadc0b

Browse files
committed
debug
1 parent af1f078 commit 1aadc0b

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

codeflash/discovery/functions_to_optimize.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import ast
4+
import json
45
import os
56
import random
67
import warnings
@@ -156,9 +157,9 @@ def get_functions_to_optimize(
156157
project_root: Path,
157158
module_root: Path,
158159
) -> tuple[dict[Path, list[FunctionToOptimize]], int]:
159-
assert (
160-
sum([bool(optimize_all), bool(replay_test), bool(file)]) <= 1
161-
), "Only one of optimize_all, replay_test, or file should be provided"
160+
assert sum([bool(optimize_all), bool(replay_test), bool(file)]) <= 1, (
161+
"Only one of optimize_all, replay_test, or file should be provided"
162+
)
162163
functions: dict[str, list[FunctionToOptimize]]
163164
with warnings.catch_warnings():
164165
warnings.simplefilter(action="ignore", category=SyntaxWarning)
@@ -457,13 +458,31 @@ def filter_functions(
457458
malformed_paths_count += 1
458459
continue
459460
if blocklist_funcs:
460-
for function in functions.copy():
461-
path = Path(function.file_path).name
462-
if path in blocklist_funcs and function.function_name in blocklist_funcs[path]:
463-
functions.remove(function)
464-
logger.debug(f"Skipping {function.function_name} in {path} as it has already been optimized")
465-
continue
466-
461+
console.print([blocklist_funcs, f"file_path: {file_path}"])
462+
filtered_functions = []
463+
for function in functions:
464+
should_keep = True
465+
466+
rel_path = str(Path(function.file_path).relative_to(project_root))
467+
file_name = Path(rel_path).name
468+
console.print(f"rel_path: {rel_path}, file_name: {file_name}")
469+
470+
if file_name in blocklist_funcs:
471+
qualified_name = (
472+
f"{function.parents[0].name}.{function.function_name}"
473+
if function.parents
474+
else function.function_name
475+
)
476+
if qualified_name in blocklist_funcs[file_name]:
477+
console.print(f"blocklist: Removing {qualified_name} in {rel_path} because it is blocklisted")
478+
should_keep = False
479+
else:
480+
console.print(
481+
f"blocklist: Keeping {qualified_name} in {rel_path} because it is not blocklisted"
482+
)
483+
if should_keep:
484+
filtered_functions.append(function)
485+
functions = filtered_functions
467486
filtered_modified_functions[file_path] = functions
468487
functions_count += len(functions)
469488
if not disable_logs:

0 commit comments

Comments
 (0)