Skip to content

Commit e220159

Browse files
authored
Merge pull request #158 from codeflash-ai/function_discovery_bug
fto discovery bug
2 parents f2a96f4 + b12e423 commit e220159

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

codeflash/benchmarking/trace_benchmarks.py

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

3+
import os
34
import re
45
import subprocess
56
from pathlib import Path
@@ -9,6 +10,11 @@
910

1011

1112
def trace_benchmarks_pytest(benchmarks_root: Path, tests_root:Path, project_root: Path, trace_file: Path, timeout:int = 300) -> None:
13+
benchmark_env = os.environ.copy()
14+
if "PYTHONPATH" not in benchmark_env:
15+
benchmark_env["PYTHONPATH"] = str(project_root)
16+
else:
17+
benchmark_env["PYTHONPATH"] += os.pathsep + str(project_root)
1218
result = subprocess.run(
1319
[
1420
SAFE_SYS_EXECUTABLE,
@@ -21,7 +27,7 @@ def trace_benchmarks_pytest(benchmarks_root: Path, tests_root:Path, project_root
2127
check=False,
2228
capture_output=True,
2329
text=True,
24-
env={"PYTHONPATH": str(project_root)},
30+
env=benchmark_env,
2531
timeout=timeout,
2632
)
2733
if result.returncode != 0:

codeflash/cli_cmds/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ def process_pyproject_config(args: Namespace) -> Namespace:
167167
# in this case, the ".." becomes outside project scope, causing issues with un-importable paths
168168
args.project_root = project_root_from_module_root(args.module_root, pyproject_file_path)
169169
args.tests_root = Path(args.tests_root).resolve()
170+
args.benchmarks_root = Path(args.benchmarks_root).resolve()
170171
args.test_project_root = project_root_from_module_root(args.tests_root, pyproject_file_path)
171172
return handle_optimize_all_arg_parsing(args)
172173

codeflash/discovery/functions_to_optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ def get_all_replay_test_functions(
299299
if valid_function.qualified_name == function_name
300300
]
301301
)
302-
if len(filtered_list):
302+
if filtered_list:
303303
filtered_valid_functions[file_path] = filtered_list
304304

305305
return filtered_valid_functions

codeflash/optimization/optimizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import ast
44
import os
5-
import time
65
import shutil
76
import tempfile
7+
import time
88
from collections import defaultdict
99
from pathlib import Path
1010
from typing import TYPE_CHECKING
@@ -97,7 +97,7 @@ def run(self) -> None:
9797
)
9898
function_benchmark_timings: dict[str, dict[BenchmarkKey, int]] = {}
9999
total_benchmark_timings: dict[BenchmarkKey, int] = {}
100-
if self.args.benchmark:
100+
if self.args.benchmark and num_optimizable_functions > 0:
101101
with progress_bar(
102102
f"Running benchmarks in {self.args.benchmarks_root}",
103103
transient=True,

0 commit comments

Comments
 (0)