8000 Change Pylint run to set cwd correctly (#322) · rookiecoder1st/python-lsp-server@89375e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89375e0

Browse files
authored
Change Pylint run to set cwd correctly (python-lsp#322)
1 parent 80d6298 commit 89375e0

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

pylsp/plugins/pylint_lint.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from subprocess import Popen, PIPE
1111
import os
1212

13-
from pylint.epylint import py_run
1413
from pylsp import hookimpl, lsp
1514

1615
try:
@@ -85,20 +84,21 @@ def lint(cls, document, is_saved, flags=''):
8584
# save.
8685
return cls.last_diags[document.path]
8786

88-
# py_run will call shlex.split on its arguments, and shlex.split does
89-
# not handle Windows paths (it will try to perform escaping). Turn
90-
# backslashes into forward slashes first to avoid this issue.
91-
path = document.path
92-
if sys.platform.startswith('win'):
93-
path = path.replace('\\', '/')
94-
95-
pylint_call = '{} -f json {}'.format(path, flags)
96-
log.debug("Calling pylint with '%s'", pylint_call)
97-
json_out, err = py_run(pylint_call, return_std=True)
98-
99-
# Get strings
100-
json_out = json_out.getvalue()
101-
err = err.getvalue()
87+
cmd = [
88+
'python',
89+
'-c',
90+
'import sys; from pylint.lint import Run; Run(sys.argv[1:])',
91+
'-f',
92+
'json',
93+
document.path
94+
] + (str(flags).split(' ') if flags else [])
95+
log.debug("Calling pylint with '%s'", ' '.join(cmd))
96+
97+
with Popen(cmd, stdout=PIPE, stderr=PIPE,
98+
cwd=document._workspace.root_path, universal_newlines=True) as process:
99+
process.wait()
100+
json_out = process.stdout.read()
101+
err = process.stderr.read()
102102

103103
if err != '':
104104
log.error("Error calling pylint: '%s'", err)

test/plugins/test_pylint_lint.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
# Copyright 2021- Python Language Server Contributors.
44

55
import contextlib
6+
from pathlib import Path
67
import os
78
import tempfile
89

910
from pylsp import lsp, uris
10-
from pylsp.workspace import Document
11+
from pylsp.workspace import Document, Workspace
1112
from pylsp.plugins import pylint_lint
1213

1314
DOC_URI = uris.from_fs_path(__file__)
@@ -90,8 +91,9 @@ def test_lint_free_pylint(config, workspace):
9091
# Can't use temp_document because it might give us a file that doesn't
9192
# match pylint's naming requirements. We should be keeping this file clean
9293
# though, so it works for a test of an empty lint.
94+
ws = Workspace(str(Path(__file__).absolute().parents[2]), workspace._endpoint)
9395
assert not pylint_lint.pylsp_lint(
94-
config, workspace, Document(uris.from_fs_path(__file__), workspace), True)
96+
config, ws, Document(uris.from_fs_path(__file__), ws), True)
9597

9698

9799
def test_lint_caching(workspace):

0 commit comments

Comments
 (0)
0