Skip to content

Commit ed32b36

Browse files
committed
Update env_utils.py
1 parent c0ae41f commit ed32b36

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

codeflash/code_utils/env_utils.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@ def check_formatter_installed(formatter_cmds: list[str], exit_on_failure: bool =
1818
if formatter_cmds[0] == "disabled":
1919
return return_code
2020
tmp_code = """print("hello world")"""
21-
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", suffix=".py") as f:
22-
f.write(tmp_code)
23-
f.flush()
24-
tmp_file = Path(f.name)
21+
with tempfile.TemporaryDirectory() as tmpdir:
22+
tmp_file = Path(tmpdir) / "test_codeflash_formatter.py"
23+
tmp_file.write_text(tmp_code, encoding="utf-8")
2524
try:
2625
format_code(formatter_cmds, tmp_file, print_status=False, exit_on_failure=exit_on_failure)
2726
except Exception:
2827
exit_with_message(
2928
"⚠️ Codeflash requires a code formatter to be installed in your environment, but none was found. Please install a supported formatter, verify the formatter-cmds in your codeflash pyproject.toml config and try again.",
3029
error_on_exit=True,
3130
)
32-
return return_code
31+
return return_code
3332

3433

3534
@lru_cache(maxsize=1)

0 commit comments

Comments
 (0)