Skip to content

Commit 6dc844e

Browse files
committed
cleanup CI fail
1 parent e8dafb3 commit 6dc844e

File tree

2 files changed

+11
-43
lines changed

2 files changed

+11
-43
lines changed

codeflash/benchmarking/function_ranker.py

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

3-
from pathlib import Path
43
from typing import TYPE_CHECKING
54

65
from codeflash.cli_cmds.console import console, logger
@@ -9,6 +8,8 @@
98
from codeflash.tracing.profile_stats import ProfileStats
109

1110
if TYPE_CHECKING:
11+
from pathlib import Path
12+
1213
from codeflash.discovery.functions_to_optimize import FunctionToOptimize
1314

1415

@@ -81,47 +82,14 @@ def load_function_stats(self) -> None:
8182
self._function_stats = {}
8283

8384
def _get_function_stats(self, function_to_optimize: FunctionToOptimize) -> dict | None:
84-
# Get all possible path variations
85-
original_path = function_to_optimize.file_path.as_posix()
86-
resolved_path = function_to_optimize.file_path.resolve().as_posix()
87-
88-
# Try to get relative path from current working directory
89-
try:
90-
cwd_relative = function_to_optimize.file_path.relative_to(Path.cwd()).as_posix()
91-
except ValueError:
92-
cwd_relative = original_path
93-
94-
# Try to get relative path from trace file directory
95-
try:
96-
trace_dir = self.trace_file_path.parent
97-
trace_relative = function_to_optimize.file_path.relative_to(trace_dir).as_posix()
98-
except ValueError:
99-
trace_relative = original_path
100-
101-
# All possible path variants to try
102-
path_variants = [original_path, resolved_path, cwd_relative, trace_relative]
103-
104-
for file_path in path_variants:
105-
key1 = f"{file_path}:{function_to_optimize.qualified_name}"
106-
key2 = f"{file_path}:{function_to_optimize.function_name}"
107-
108-
stats = self._function_stats.get(key1)
109-
if stats is not None:
110-
return stats
111-
stats = self._function_stats.get(key2)
112-
if stats is not None:
113-
return stats
114-
115-
# Try fuzzy matching as last resort - match by function name and filename
116-
target_filename = function_to_optimize.file_path.name
117-
for key, stats in self._function_stats.items():
118-
if stats.get("function_name") == function_to_optimize.function_name and (
119-
key.endswith(f"/{target_filename}") or target_filename in key
120-
):
121-
return stats
122-
123-
logger.debug(f"Could not find stats for function {function_to_optimize.function_name} in {original_path}")
124-
return None
85+
file_path = function_to_optimize.file_path.as_posix()
86+
key1 = f"{file_path}:{function_to_optimize.qualified_name}"
87+
key2 = f"{file_path}:{function_to_optimize.function_name}"
88+
89+
stats = self._function_stats.get(key1)
90+
if stats is not None:
91+
return stats
92+
return self._function_stats.get(key2)
12593

12694
def get_function_ttx_score(self, function_to_optimize: FunctionToOptimize) -> float:
12795
stats = self._get_function_stats(function_to_optimize)

tests/test_function_ranker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def trace_file():
1414

1515
@pytest.fixture
1616
def workload_functions():
17-
workloads_file = Path(__file__).parent.parent / "code_to_optimize/code_directories/simple_tracer_e2e/workload.py"
17+
workloads_file = (Path(__file__).parent.parent / "code_to_optimize/code_directories/simple_tracer_e2e/workload.py").resolve()
1818
functions_dict = find_all_functions_in_file(workloads_file)
1919
all_functions = []
2020
for functions_list in functions_dict.values():

0 commit comments

Comments
 (0)