42
42
# https://github.com/python-lsp/python-lsp-server/blob/v1.0.1/pylsp/plugins/pylint_lint.py#L55-L62
43
43
last_diagnostics : Dict [str , List [Dict [str , Any ]]] = collections .defaultdict (list )
44
44
45
+ # Windows started opening opening a cmd-like window for every subprocess call
46
+ # This flag prevents that.
47
+ # This flag is new in python 3.7
48
+ # THis flag only exists on Windows
49
+ windows_flag : Dict [str , int ] = (
50
+ {"startupinfo" : subprocess .CREATE_NO_WINDOW } if os .name == "nt" else {} # type: ignore
51
+ )
52
+
45
53
46
54
def parse_line (line : str , document : Optional [Document ] = None ) -> Optional [Dict [str , Any ]]:
47
55
"""
@@ -214,7 +222,7 @@ def pylsp_lint(
214
222
# -> use mypy on path
215
223
log .info ("executing mypy args = %s on path" , args )
216
224
completed_process = subprocess .run (
217
- ["mypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
225
+ ["mypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** windows_flag
218
226
)
219
227
report = completed_process .stdout .decode ()
220
228
errors = completed_process .stderr .decode ()
@@ -234,15 +242,15 @@ def pylsp_lint(
234
242
# dmypy exists on path
235
243
# -> use mypy on path
236
244
completed_process = subprocess .run (
237
- ["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE
245
+ ["dmypy" , * apply_overrides (args , overrides )], stderr = subprocess .PIPE , ** windows_flag
238
246
)
239
247
_err = completed_process .stderr .decode ()
240
248
_status = completed_process .returncode
241
249
if _status != 0 :
242
250
log .info (
243
251
"restarting dmypy from status: %s message: %s via path" , _status , _err .strip ()
244
252
)
245
- subprocess .run (["dmypy" , "kill" ])
253
+ subprocess .run (["dmypy" , "kill" ], ** windows_flag )
246
254
else :
247
255
# dmypy does not exist on path, but must exist in the env pylsp-mypy is installed in
248
256
# -> use dmypy via api
@@ -261,7 +269,7 @@ def pylsp_lint(
261
269
# -> use mypy on path
262
270
log .info ("dmypy run args = %s via path" , args )
263
271
completed_process = subprocess .run (
264
- ["dmypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE
272
+ ["dmypy" , * args ], stdout = subprocess .PIPE , stderr = subprocess .PIPE , ** windows_flag
265
273
)
266
274
report = completed_process .stdout .decode ()
267
275
errors = completed_process .stderr .decode ()
0 commit comments