Skip to content

Commit e837c55

Browse files
authored
Don't set cwd in Popen kwargs when document root is empty (flake8) (#434)
1 parent e5c913d commit e837c55

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pylsp/plugins/flake8_lint.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)