2
2
import tempfile
3
3
import json
4
4
import os
5
+ import sys
5
6
import logging
6
7
logger = logging .getLogger (__name__ )
7
8
8
9
9
10
def ruff_check (code : str , prefix : str | None = None ) -> list [dict ]:
10
11
"""
11
12
Lints Python source code using Ruff.
12
-
13
+
13
14
Args:
14
15
code (str): The Python source code to lint.
15
16
"""
@@ -25,9 +26,14 @@ def ruff_check(code: str, prefix: str | None = None) -> list[dict]:
25
26
tmp_file_path = tmp_file .name
26
27
print (tmp_file .name )
27
28
cmd = ["ruff" , "check" , tmp_file_path , "--output-format" , "json" ]
29
+
30
+ # Set creation flags for Windows to prevent console window from appearing
31
+ creation_flags = subprocess .CREATE_NO_WINDOW if sys .platform == 'win32' else 0
32
+
28
33
try :
29
34
process = subprocess .Popen (cmd , stdout = subprocess .PIPE ,
30
- stderr = subprocess .PIPE , text = True )
35
+ stderr = subprocess .PIPE , text = True ,
36
+ creationflags = creation_flags )
31
37
stdout , stderr = process .communicate ()
32
38
except Exception as e :
33
39
logger .error (f'failed to invoke ruff: { e } ' )
@@ -49,4 +55,4 @@ def ruff_check(code: str, prefix: str | None = None) -> list[dict]:
49
55
'code' : message ['code' ],
50
56
'message' : message ['message' ],
51
57
})
52
- return formatted_result
58
+ return formatted_result
0 commit comments