@@ -109,12 +109,13 @@ def run_flake8(flake8_executable, args, document):
109109 )
110110
111111 log .debug ("Calling %s with args: '%s'" , flake8_executable , args )
112+ popen_kwargs = {}
113+ if cwd := document ._workspace .root_path :
114+ popen_kwargs ["cwd" ] = cwd
112115 try :
113116 cmd = [flake8_executable ]
114117 cmd .extend (args )
115- p = Popen (
116- cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE , cwd = document ._workspace .root_path
117- )
118+ p = Popen (cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE , ** popen_kwargs )
118119 except IOError :
119120 log .debug (
120121 "Can't execute %s. Trying with '%s -m flake8'" ,
@@ -124,7 +125,7 @@ def run_flake8(flake8_executable, args, document):
124125 cmd = [sys .executable , "-m" , "flake8" ]
125126 cmd .extend (args )
126127 p = Popen ( # pylint: disable=consider-using-with
127- cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE , cwd = document . _workspace . root_path
128+ cmd , stdin = PIPE , stdout = PIPE , stderr = PIPE , ** popen_kwargs
128129 )
129130 (stdout , stderr ) = p .communicate (document .source .encode ())
130131 if stderr :
0 commit comments