1
0
forked from VimPlug/jedi

Add added_sys_path to Project, fixes #1334

This commit is contained in:
Dave Halter
2020-01-31 00:08:24 +01:00
parent 4a1d9a9116
commit 251ff447bc
2 changed files with 14 additions and 2 deletions

View File

@@ -61,11 +61,13 @@ class Project(object):
:param sys_path: list of str. You can override the sys path if you
want. By default the ``sys.path.`` is generated from the
environment (virtualenvs, etc).
:param added_sys_path: list of str. Adds these paths at the end of the
sys path.
:param smart_sys_path: If this is enabled (default), adds paths from
local directories. Otherwise you will have to rely on your packages
being properly configured on the ``sys.path``.
"""
def py2_comp(path, environment=None, sys_path=None,
def py2_comp(path, environment=None, sys_path=None, added_sys_path=True,
smart_sys_path=True, _django=False):
self._path = os.path.abspath(path)
if isinstance(environment, SameEnvironment):
@@ -74,6 +76,8 @@ class Project(object):
self._sys_path = sys_path
self._smart_sys_path = smart_sys_path
self._django = _django
self.added_sys_path = []
"""The sys path that is going to be added at the end of the """
py2_comp(path, **kwargs)
@@ -91,7 +95,7 @@ class Project(object):
sys_path.remove('')
except ValueError:
pass
return sys_path
return sys_path + self.added_sys_path
@inference_state_as_method_param_cache()
def _get_sys_path(self, inference_state, environment=None,

View File

@@ -2,6 +2,7 @@ import os
from ..helpers import get_example_dir, set_cwd, root_dir
from jedi import Interpreter
from jedi.api import Project, get_default_project
def test_django_default_project(Script):
@@ -22,3 +23,10 @@ def test_interpreter_project_path():
with set_cwd(dir):
project = Interpreter('', [locals()])._inference_state.project
assert project._path == dir
def test_added_sys_path(inference_state):
project = get_default_project()
p = '/some_random_path'
project.added_sys_path = [p]
assert p in project._get_base_sys_path(inference_state)