Skip to content

Commit

Permalink
* add site-packages to jedi configuration; see davidhalter/jedi#1540
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Clary committed Jun 25, 2020
1 parent 56a53b5 commit 0a149b9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 0 additions & 1 deletion spyder/app/tests/test_mainwindow.py
Expand Up @@ -56,7 +56,6 @@
from spyder.plugins.help.tests.test_plugin import check_text
from spyder.plugins.ipythonconsole.utils.kernelspec import SpyderKernelSpec
from spyder.py3compat import PY2, to_text_string
from spyder.utils.programs import is_module_installed
from spyder.widgets.dock import DockTitleBar
from spyder.utils.misc import remove_backslashes

Expand Down
14 changes: 12 additions & 2 deletions spyder/plugins/completion/languageserver/plugin.py
Expand Up @@ -26,6 +26,8 @@
from spyder.config.manager import CONF
from spyder.api.completion import SpyderCompletionPlugin
from spyder.utils.misc import check_connection_port, getcwd_or_home
from spyder.utils.programs import get_python_site_packages # TODO: issue 12664
from spyder.utils.conda import is_conda_env # TODO: issue 12664
from spyder.plugins.completion.languageserver import LSP_LANGUAGES
from spyder.plugins.completion.languageserver.client import LSPClient
from spyder.plugins.completion.languageserver.confpage import (
Expand Down Expand Up @@ -623,15 +625,23 @@ def generate_python_config(self):
}

# Jedi configuration
extra_paths = self.get_option('spyder_pythonpath', section='main',
default=[])
if self.get_option('default', section='main_interpreter'):
environment = None
else:
environment = self.get_option('custom_interpreter',
section='main_interpreter')

# jedi can miss the site-package: see davidhalter/jedi#1540.
# TODO: issue #12664; Remove if block when pyls adopts jedi>0.17.0.
if (not is_conda_env(pyexec=sys.executable)
and is_conda_env(pyexec=environment)):
extra_paths += get_python_site_packages(environment)

jedi = {
'environment': environment,
'extra_paths': self.get_option('spyder_pythonpath',
section='main', default=[]),
'extra_paths': extra_paths,
}
jedi_completion = {
'enabled': self.get_option('code_completion'),
Expand Down
19 changes: 19 additions & 0 deletions spyder/utils/programs.py
Expand Up @@ -24,6 +24,7 @@
import tempfile
import threading
import time
import ast # TODO: issue #12664

# Third party imports
import psutil
Expand Down Expand Up @@ -980,6 +981,24 @@ def check_python_help(filename):
return False


def get_python_site_packages(pyexec):
"""Get the site-packages for a given python executable.
TODO: issue #12664. This function is only used as part of a patch for
davidhalter/jedi#1540 and can be removed when python-language-server
adopts jedi>0.17.0 (palantir/python-language-server#744).
"""
script = 'import site; print(site.getsitepackages())'
try:
# clean environment is more reliable
proc = run_program(pyexec, ['-c', script], env={})
stdout, stderr = proc.communicate()
pkgs = ast.literal_eval(stdout.decode())
except Exception:
pkgs = []

return pkgs


def is_spyder_process(pid):
"""
Test whether given PID belongs to a Spyder process.
Expand Down

0 comments on commit 0a149b9

Please sign in to comment.