| 
1 | 1 | from __future__ import annotations  | 
2 | 2 | 
 
  | 
3 | 3 | import ast  | 
 | 4 | +import json  | 
4 | 5 | import os  | 
5 | 6 | import random  | 
6 | 7 | import warnings  | 
@@ -156,9 +157,9 @@ def get_functions_to_optimize(  | 
156 | 157 |     project_root: Path,  | 
157 | 158 |     module_root: Path,  | 
158 | 159 | ) -> 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 | +    )  | 
162 | 163 |     functions: dict[str, list[FunctionToOptimize]]  | 
163 | 164 |     with warnings.catch_warnings():  | 
164 | 165 |         warnings.simplefilter(action="ignore", category=SyntaxWarning)  | 
@@ -457,13 +458,31 @@ def filter_functions(  | 
457 | 458 |             malformed_paths_count += 1  | 
458 | 459 |             continue  | 
459 | 460 |         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  | 
467 | 486 |         filtered_modified_functions[file_path] = functions  | 
468 | 487 |         functions_count += len(functions)  | 
469 | 488 |     if not disable_logs:  | 
 | 
0 commit comments