Skip to content

Commit b497210

Browse files
committed
refactoring
1 parent 2ed293e commit b497210

File tree

1 file changed

+2
-15
lines changed

1 file changed

+2
-15
lines changed

codeflash/code_utils/env_utils.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from typing import Optional
1010

1111
from codeflash.cli_cmds.console import logger
12+
from codeflash.code_utils.formatter import format_code
1213
from codeflash.code_utils.shell_utils import read_api_key_from_shell_config
1314

1415

@@ -28,22 +29,8 @@ def check_formatter_installed(formatter_cmds: list[str]) -> bool:
2829
f.write(tmp_code)
2930
f.flush()
3031
tmp_file = Path(f.name)
31-
file_token = "$file" # noqa: S105
32-
for command in set(formatter_cmds):
33-
formatter_cmd_list = shlex.split(command, posix=os.name != "nt")
34-
formatter_cmd_list = [tmp_file.as_posix() if chunk == file_token else chunk for chunk in formatter_cmd_list]
35-
try:
36-
result = subprocess.run(formatter_cmd_list, capture_output=True, check=False)
37-
except (FileNotFoundError, NotADirectoryError):
38-
return_code = False
39-
break
40-
if result.returncode:
41-
return_code = False
42-
break
32+
format_code(formatter_cmds, tmp_file)
4333
tmp_file.unlink(missing_ok=True)
44-
if not return_code:
45-
msg = f"Error running formatter command: {command}"
46-
raise FormatterNotFoundError(msg)
4734
return return_code
4835

4936

0 commit comments

Comments
 (0)