From af21eda82e624d1c8ad8c8d9e45613228f6fffb6 Mon Sep 17 00:00:00 2001 From: Stephen Macke Date: Wed, 6 Sep 2023 17:39:53 -0700 Subject: [PATCH 1/2] dont set cwd in popen kwargs when document root is empty --- pylsp/plugins/flake8_lint.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 70452cf9..4c1addd8 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -109,11 +109,14 @@ 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 + cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs ) except IOError: log.debug( @@ -124,7 +127,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: From 6a416b2a9f981bf3b363a83275aec59b99691b94 Mon Sep 17 00:00:00 2001 From: Stephen Macke Date: Thu, 7 Sep 2023 20:02:48 -0700 Subject: [PATCH 2/2] blacken --- pylsp/plugins/flake8_lint.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pylsp/plugins/flake8_lint.py b/pylsp/plugins/flake8_lint.py index 4c1addd8..068585ef 100644 --- a/pylsp/plugins/flake8_lint.py +++ b/pylsp/plugins/flake8_lint.py @@ -115,9 +115,7 @@ def run_flake8(flake8_executable, args, document): try: cmd = [flake8_executable] cmd.extend(args) - p = Popen( - cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs - ) + p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, **popen_kwargs) except IOError: log.debug( "Can't execute %s. Trying with '%s -m flake8'",