Skip to content

Commit a394cd8

Browse files
committed
Merge branch 'function_discovery_bug' into context-import-bug
2 parents c8710fa + ecfea1a commit a394cd8

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,11 +201,13 @@ def get_functions_to_optimize(
201201
functions, test_cfg.tests_root, ignore_paths, project_root, module_root
202202
)
203203
logger.info(f"Found {functions_count} function{'s' if functions_count > 1 else ''} to optimize")
204+
logger.info(f"{filtered_modified_functions}")
204205
return filtered_modified_functions, functions_count
205206

206207

207208
def get_functions_within_git_diff() -> dict[str, list[FunctionToOptimize]]:
208209
modified_lines: dict[str, list[int]] = get_git_diff(uncommitted_changes=False)
210+
logger.info(f"modified lines: {modified_lines}")
209211
modified_functions: dict[str, list[FunctionToOptimize]] = {}
210212
for path_str in modified_lines:
211213
path = Path(path_str)
@@ -299,7 +301,7 @@ def get_all_replay_test_functions(
299301
if valid_function.qualified_name == function_name
300302
]
301303
)
302-
if len(filtered_list):
304+
if filtered_list:
303305
filtered_valid_functions[file_path] = filtered_list
304306

305307
return filtered_valid_functions

codeflash/optimization/optimizer.py

Lines changed: 3 additions & 3 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
@@ -83,7 +83,7 @@ def run(self) -> None:
8383
function_optimizer = None
8484
file_to_funcs_to_optimize: dict[Path, list[FunctionToOptimize]]
8585
num_optimizable_functions: int
86-
86+
logger.info(self.args)
8787
# discover functions
8888
(file_to_funcs_to_optimize, num_optimizable_functions) = get_functions_to_optimize(
8989
optimize_all=self.args.all,
@@ -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)