File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed
Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -15,18 +15,21 @@ def check_formatter_installed(formatter_cmds: list[str]) -> bool:
1515 if formatter_cmds [0 ] == "disabled" :
1616 return return_code
1717 tmp_code = """print("hello world")"""
18- tmp_file = tempfile .NamedTemporaryFile (suffix = ".py" )
19- Path (tmp_file .name ).write_text (tmp_code , encoding = "utf8" )
20- file_token = "$file" # noqa: S105
21- for command in set (formatter_cmds ):
22- formatter_cmd_list = shlex .split (command , posix = os .name != "nt" )
23- formatter_cmd_list = [tmp_file .as_posix () if chunk == file_token else chunk for chunk in formatter_cmd_list ]
24- result = subprocess .run (formatter_cmd_list , capture_output = True , check = False )
25- if result .returncode :
26- return_code = False
27- break
28- tmp_file .close ()
18+ with tempfile .NamedTemporaryFile (mode = "w" , encoding = "utf-8" , suffix = ".py" ) as f :
19+ f .write (tmp_code )
20+ f .flush ()
21+ tmp_file = Path (f .name )
22+ file_token = "$file" # noqa: S105
23+ for command in set (formatter_cmds ):
24+ formatter_cmd_list = shlex .split (command , posix = os .name != "nt" )
25+ formatter_cmd_list = [tmp_file .as_posix () if chunk == file_token else chunk for chunk in formatter_cmd_list ]
26+ result = subprocess .run (formatter_cmd_list , capture_output = True , check = False )
27+ if result .returncode :
28+ return_code = False
29+ break
2930 tmp_file .unlink (missing_ok = True )
31+ if not return_code :
32+ raise logger .error (f"Error running formatter command: { command } " )
3033 return return_code
3134
3235
You can’t perform that action at this time.
0 commit comments