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 Apr 10, 2020
1 parent 8b86d87 commit afd6229
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 8 additions & 2 deletions spyder/plugins/completion/languageserver/plugin.py
Expand Up @@ -26,6 +26,7 @@
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
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 @@ -574,15 +575,20 @@ 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
# https://github.com/davidhalter/jedi/issues/1540
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
14 changes: 14 additions & 0 deletions spyder/utils/programs.py
Expand Up @@ -24,6 +24,7 @@
import tempfile
import threading
import time
import ast

# Third party imports
import psutil
Expand Down Expand Up @@ -967,6 +968,19 @@ def check_python_help(filename):
return False


def get_python_site_packages(pyexec):
"""Get the site-packages for a given python executable"""
script = 'import site; print(site.getsitepackages())'
try:
proc = run_program('env', ['-i', pyexec, '-c', script])
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 afd6229

Please sign in to comment.