Skip to content

Commit a4301ce

Browse files
committed
pass
1 parent cf55e96 commit a4301ce

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from codeflash.cli_cmds.console import logger
1111

12+
_tmpdir = TemporaryDirectory(prefix="codeflash_")
1213

1314
def get_qualified_name(module_name: str, full_qualified_name: str) -> str:
1415
if not full_qualified_name:
@@ -78,10 +79,12 @@ def get_all_function_names(code: str) -> tuple[bool, list[str]]:
7879
return True, function_names
7980

8081

81-
def get_run_tmp_file(file_path: Path) -> Path:
82+
def get_run_tmp_file(file_path: Path | str) -> Path:
8283
if not hasattr(get_run_tmp_file, "tmpdir"):
83-
get_run_tmp_file.tmpdir = TemporaryDirectory(prefix="codeflash_")
84-
return Path(get_run_tmp_file.tmpdir.name) / file_path
84+
get_run_tmp_file.tmpdir = _tmpdir
85+
if isinstance(file_path, str):
86+
file_path = Path(file_path)
87+
return (Path(get_run_tmp_file.tmpdir.name) / file_path).resolve()
8588

8689

8790
def path_belongs_to_site_packages(file_path: Path) -> bool:

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef, test_class_name: str | None =
213213
args=[
214214
ast.JoinedStr(
215215
values=[
216-
ast.Constant(value=f"{get_run_tmp_file(Path('test_return_values_'))}"),
216+
ast.Constant(value=get_run_tmp_file("test_return_values_").as_posix()),
217217
ast.FormattedValue(
218218
value=ast.Name(id="codeflash_iteration", ctx=ast.Load()),
219219
conversion=-1,

tests/test_get_helper_code.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,12 @@ def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
213213
lifespan=self.__duration__,
214214
)
215215
'''
216-
with tempfile.NamedTemporaryFile(mode="w") as f:
217-
f.write(code)
218-
f.flush()
219-
file_path = Path(f.name).resolve()
216+
with tempfile.TemporaryDirectory() as temp_dir:
217+
temp_file_path = Path(temp_dir) / "temp_code.py"
218+
with open(temp_file_path, "w") as f:
219+
f.write(code)
220+
f.flush()
221+
file_path = temp_file_path.resolve()
220222
project_root_path = file_path.parent.resolve()
221223
function_to_optimize = FunctionToOptimize(
222224
function_name="__call__",

0 commit comments

Comments
 (0)