Use the evaluate.project sys path stuff for api.project

This commit is contained in:
Dave Halter
2018-01-16 10:03:28 +01:00
parent c6240d5453
commit ddaf175b11

View File

@@ -5,6 +5,9 @@ from jedi._compatibility import FileNotFoundError
from jedi.api.environment import DefaultEnvironment, \ from jedi.api.environment import DefaultEnvironment, \
get_default_environment, from_executable get_default_environment, from_executable
from jedi.api.exceptions import WrongVersion from jedi.api.exceptions import WrongVersion
from jedi._compatibility import force_unicode
from jedi.evaluate.sys_path import detect_additional_paths
from jedi.evaluate.cache import evaluator_function_cache
_CONFIG_FOLDER = '.jedi' _CONFIG_FOLDER = '.jedi'
_CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'MANIFEST.in' _CONTAINS_POTENTIAL_PROJECT = 'setup.py', '.git', '.hg', 'MANIFEST.in'
@@ -44,17 +47,18 @@ class Project(object):
""" """
:param path: The base path for this project. :param path: The base path for this project.
""" """
def py2_comp(path, environment=None, sys_path=None): def py2_comp(path, environment=None, sys_path=None, explicit=False):
self._path = path self._path = path
if isinstance(environment, DefaultEnvironment): if isinstance(environment, DefaultEnvironment):
self._environment = environment self._environment = environment
self._executable = environment._executable self._executable = environment._executable
self._sys_path = sys_path self._sys_path = sys_path
self._explicit = explicit
py2_comp(path, **kwargs) py2_comp(path, **kwargs)
def _get_sys_path(self, environment=None): def _get_base_sys_path(self, environment=None):
if self._sys_path is not None: if self._sys_path is not None:
return self._sys_path return self._sys_path
@@ -64,6 +68,27 @@ class Project(object):
return environment.get_sys_path() return environment.get_sys_path()
@evaluator_function_cache()
def _get_sys_path(self, evaluator, environment=None):
"""
Keep this method private for all users of jedi. However internally this
one is used like a public method.
"""
sys_path = list(self._get_base_sys_path(environment))
try:
sys_path.remove('')
except ValueError:
pass
if self._script_path is None:
return sys_path
added_paths = map(
force_unicode,
detect_additional_paths(self._evaluator, self._script_path)
)
return sys_path + list(added_paths)
def save(self): def save(self):
data = dict(self.__dict__) data = dict(self.__dict__)
for attribute in self._serializer_ignore_attributes: for attribute in self._serializer_ignore_attributes: