Skip to content

Commit

Permalink
Don't set cwd in Popen kwargs when document root is empty (flake8) (#434
Browse files Browse the repository at this point in the history
)
  • Loading branch information
smacke authored Sep 8, 2023
1 parent e5c913d commit e837c55
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pylsp/plugins/flake8_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ def run_flake8(flake8_executable, args, document):
)

log.debug("Calling %s with args: '%s'", flake8_executable, args)
popen_kwargs = {}
if cwd := document._workspace.root_path:
popen_kwargs["cwd"] = cwd
try:
cmd = [flake8_executable]
cmd.extend(args)
p = Popen(
cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=document._workspace.root_path
)
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs)
except IOError:
log.debug(
"Can't execute %s. Trying with '%s -m flake8'",
Expand All @@ -124,7 +125,7 @@ def run_flake8(flake8_executable, args, document):
cmd = [sys.executable, "-m", "flake8"]
cmd.extend(args)
p = Popen( # pylint: disable=consider-using-with
cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, cwd=document._workspace.root_path
cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs
)
(stdout, stderr) = p.communicate(document.source.encode())
if stderr:
Expand Down

0 comments on commit e837c55

Please sign in to comment.