Skip to content

Commit addba28

Browse files
committed
Make pylint respect libraries installed into extra paths
For example, jedi respects VIRTUAL_ENV environment variable at finding out libraries. Therefore, (virtualenv) runtime for pyls/jedi can be separated from one for the target workspace. On the other hand, pylint does not respect VIRTUAL_ENV, and might cause unintentional "import-error" (E0401) for libraries installed in such virtualenv, even though jedi can recognize them. In order to make pylint respect libraries installed into extra paths, this commit uses Document.sys_path() instead of sys.path of current pyls process, at spawning pylint. At this commit, Document.sys_path() should respect source roots in the workspace, VIRTUAL_ENV, PYTHONPATH, and plugins.jedi.extra_paths configuration.
1 parent bf5f3c4 commit addba28

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pyls/plugins/pylint_lint.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,19 @@
1616

1717
if sys.version_info.major == 2:
1818
from StringIO import StringIO
19+
20+
# subprocess.Popen() on Windows expects that env contains only
21+
# "str" keys/values (= "bytes" for Python2.x, "unicode" for
22+
# Python3.x), even though pyls treats all path values as "unicode"
23+
# regardless of Python version
24+
def stringify(u):
25+
return u.encode('utf-8')
1926
else:
2027
from io import StringIO
2128

29+
def stringify(u):
30+
return u
31+
2232
log = logging.getLogger(__name__)
2333

2434

@@ -33,7 +43,7 @@ def spawn_pylint(document, flags):
3343
path = path.replace('\\', '/')
3444

3545
env = dict(os.environ)
36-
env["PYTHONPATH"] = os.pathsep.join(sys.path)
46+
env["PYTHONPATH"] = stringify(os.pathsep.join(document.sys_path()))
3747

3848
# Detect if we use Python as executable or not, else default to `python`
3949
executable = sys.executable if "python" in sys.executable else "python"

0 commit comments

Comments
 (0)