From addba28fce36e118ffba15bf42707d0da2970ec4 Mon Sep 17 00:00:00 2001 From: FUJIWARA Katsunori Date: Fri, 17 Jan 2020 18:00:50 +0900 Subject: [PATCH] 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. --- pyls/plugins/pylint_lint.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pyls/plugins/pylint_lint.py b/pyls/plugins/pylint_lint.py index 852d2f62..13836ac2 100644 --- a/pyls/plugins/pylint_lint.py +++ b/pyls/plugins/pylint_lint.py @@ -16,9 +16,19 @@ if sys.version_info.major == 2: from StringIO import StringIO + + # subprocess.Popen() on Windows expects that env contains only + # "str" keys/values (= "bytes" for Python2.x, "unicode" for + # Python3.x), even though pyls treats all path values as "unicode" + # regardless of Python version + def stringify(u): + return u.encode('utf-8') else: from io import StringIO + def stringify(u): + return u + log = logging.getLogger(__name__) @@ -33,7 +43,7 @@ def spawn_pylint(document, flags): path = path.replace('\\', '/') env = dict(os.environ) - env["PYTHONPATH"] = os.pathsep.join(sys.path) + env["PYTHONPATH"] = stringify(os.pathsep.join(document.sys_path())) # Detect if we use Python as executable or not, else default to `python` executable = sys.executable if "python" in sys.executable else "python"