Skip to content

Commit 586f5af

Browse files
committed
path normalization and tempdir fixes for windows
1 parent 8b2b37a commit 586f5af

21 files changed

+593
-1212
lines changed

codeflash/benchmarking/replay_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def create_trace_replay_test_code(
162162
benchmark_function_name=benchmark_function_name,
163163
orig_function_name=function_name,
164164
function_name=alias,
165-
file_path=file_path,
165+
file_path=Path(file_path).as_posix(),
166166
max_run_count=max_run_count,
167167
)
168168
else:
@@ -176,7 +176,7 @@ def create_trace_replay_test_code(
176176
test_body = test_class_method_body.format(
177177
benchmark_function_name=benchmark_function_name,
178178
orig_function_name=function_name,
179-
file_path=file_path,
179+
file_path=Path(file_path).as_posix(),
180180
class_name_alias=class_name_alias,
181181
class_name=class_name,
182182
method_name=method_name,
@@ -187,7 +187,7 @@ def create_trace_replay_test_code(
187187
test_body = test_static_method_body.format(
188188
benchmark_function_name=benchmark_function_name,
189189
orig_function_name=function_name,
190-
file_path=file_path,
190+
file_path=Path(file_path).as_posix(),
191191
class_name_alias=class_name_alias,
192192
class_name=class_name,
193193
method_name=method_name,
@@ -198,7 +198,7 @@ def create_trace_replay_test_code(
198198
test_body = test_method_body.format(
199199
benchmark_function_name=benchmark_function_name,
200200
orig_function_name=function_name,
201-
file_path=file_path,
201+
file_path=Path(file_path).as_posix(),
202202
class_name_alias=class_name_alias,
203203
class_name=class_name,
204204
method_name=method_name,

codeflash/code_utils/code_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ def get_run_tmp_file(file_path: Path) -> Path:
171171

172172

173173
def path_belongs_to_site_packages(file_path: Path) -> bool:
174+
file_path_resolved = file_path.resolve()
174175
site_packages = [Path(p) for p in site.getsitepackages()]
175-
return any(file_path.resolve().is_relative_to(site_package_path) for site_package_path in site_packages)
176+
return any(file_path_resolved.is_relative_to(site_package_path) for site_package_path in site_packages)
176177

177178

178179
def is_class_defined_in_file(class_name: str, file_path: Path) -> bool:

codeflash/code_utils/coverage_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def generate_candidates(source_code_path: Path) -> list[str]:
4545
current_path = source_code_path.parent
4646

4747
while current_path != current_path.parent:
48-
candidate_path = str(Path(current_path.name) / candidates[-1])
48+
candidate_path = (Path(current_path.name) / candidates[-1]).as_posix()
4949
candidates.append(candidate_path)
5050
current_path = current_path.parent
5151

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ def visit_FunctionDef(self, node: ast.FunctionDef, test_class_name: str | None =
212212
args=[
213213
ast.JoinedStr(
214214
values=[
215-
ast.Constant(value=f"{get_run_tmp_file(Path('test_return_values_'))}"),
215+
ast.Constant(
216+
value=f"{get_run_tmp_file(Path('test_return_values_')).as_posix()}"
217+
),
216218
ast.FormattedValue(
217219
value=ast.Name(id="codeflash_iteration", ctx=ast.Load()),
218220
conversion=-1,

codeflash/models/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def markdown(self) -> str:
147147
"""Returns the markdown representation of the code, including the file path where possible."""
148148
return "\n".join(
149149
[
150-
f"```python{':' + str(code_string.file_path) if code_string.file_path else ''}\n{code_string.code.strip()}\n```"
150+
f"```python{':' + code_string.file_path.as_posix() if code_string.file_path else ''}\n{code_string.code.strip()}\n```"
151151
for code_string in self.code_strings
152152
]
153153
)

codeflash/result/create_pr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def existing_tests_source_for(
104104
if greater:
105105
rows.append(
106106
[
107-
f"`{filename}::{qualified_name}`",
107+
f"`{filename.as_posix()}::{qualified_name}`",
108108
f"{print_original_runtime}",
109109
f"{print_optimized_runtime}",
110110
f"⚠️{perf_gain}%",
@@ -113,7 +113,7 @@ def existing_tests_source_for(
113113
else:
114114
rows.append(
115115
[
116-
f"`{filename}::{qualified_name}`",
116+
f"`{filename.as_posix()}::{qualified_name}`",
117117
f"{print_original_runtime}",
118118
f"{print_optimized_runtime}",
119119
f"✅{perf_gain}%",

codeflash/verification/instrument_codeflash_capture.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def instrument_codeflash_capture(
3333
modified_code = add_codeflash_capture_to_init(
3434
target_classes={class_parent.name},
3535
fto_name=function_to_optimize.function_name,
36-
tmp_dir_path=str(get_run_tmp_file(Path("test_return_values"))),
36+
tmp_dir_path=get_run_tmp_file(Path("test_return_values")).as_posix(),
3737
code=original_code,
3838
tests_root=tests_root,
3939
is_fto=True,
@@ -46,7 +46,7 @@ def instrument_codeflash_capture(
4646
modified_code = add_codeflash_capture_to_init(
4747
target_classes=helper_classes,
4848
fto_name=function_to_optimize.function_name,
49-
tmp_dir_path=str(get_run_tmp_file(Path("test_return_values"))),
49+
tmp_dir_path=get_run_tmp_file(Path("test_return_values")).as_posix(),
5050
code=original_code,
5151
tests_root=tests_root,
5252
is_fto=False,
@@ -124,7 +124,7 @@ def visit_ClassDef(self, node: ast.ClassDef) -> ast.ClassDef:
124124
keywords=[
125125
ast.keyword(arg="function_name", value=ast.Constant(value=f"{node.name}.__init__")),
126126
ast.keyword(arg="tmp_dir_path", value=ast.Constant(value=self.tmp_dir_path)),
127-
ast.keyword(arg="tests_root", value=ast.Constant(value=str(self.tests_root))),
127+
ast.keyword(arg="tests_root", value=ast.Constant(value=self.tests_root.as_posix())),
128128
ast.keyword(arg="is_fto", value=ast.Constant(value=self.is_fto)),
129129
],
130130
)

0 commit comments

Comments
 (0)