1
0
forked from VimPlug/jedi

Try to migrate to the new project API

This commit is contained in:
Dave Halter
2018-01-16 23:56:35 +01:00
parent 9b9587a9dd
commit fe813292cf
10 changed files with 29 additions and 20 deletions

View File

@@ -104,7 +104,6 @@ class Evaluator(object):
self.is_analysis = False
self.project = project
self.access_cache = {}
project.add_evaluator(self)
self.reset_recursion_limitations()
@@ -117,6 +116,10 @@ class Evaluator(object):
self.recursion_detector = recursion.RecursionDetector()
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
def get_sys_path(self):
"""Convenience function"""
return self.project._get_sys_path(self, environment=self.environment)
def eval_element(self, context, element):
if isinstance(context, CompForContext):
return eval_node(context, element)

View File

@@ -59,7 +59,7 @@ def evaluator_method_cache(default=_NO_DEFAULT):
return decorator
def _memoize_meta_class():
def evaluator_as_method_param_cache():
def decorator(call):
return _memoize_default(second_arg_is_evaluator=True)(call)
@@ -72,6 +72,6 @@ class CachedMetaClass(type):
class initializations. Either you do it this way or with decorators, but
with decorators you lose class access (isinstance, etc).
"""
@_memoize_meta_class()
@evaluator_as_method_param_cache()
def __call__(self, *args, **kwargs):
return super(CachedMetaClass, self).__call__(*args, **kwargs)

View File

@@ -135,7 +135,7 @@ def create_access(evaluator, obj):
def load_module(evaluator, path=None, name=None, sys_path=None):
if sys_path is None:
sys_path = list(evaluator.project.sys_path)
sys_path = list(evaluator.get_sys_path())
if path is not None:
dotted_path = dotted_from_fs_path(path, sys_path=sys_path)
else:

View File

@@ -230,7 +230,7 @@ class Listener(object):
except KeyError:
from jedi.api.environment import InterpreterEnvironment
evaluator = Evaluator(
project=project.Project(),
project=None,
environment=InterpreterEnvironment()
)
self._evaluators[evaluator_id] = evaluator

View File

@@ -137,7 +137,7 @@ class ModuleContext(use_metaclass(CachedMetaClass, TreeContext)):
return self.py__name__()
def _py__path__(self):
search_path = self.evaluator.project.sys_path
search_path = self.evaluator.get_sys_path()
init_path = self.py__file__()
if os.path.basename(init_path) == '__init__.py':
with open(init_path, 'rb') as f:

View File

@@ -243,7 +243,7 @@ class Importer(object):
def sys_path_with_modifications(self):
in_path = []
sys_path_mod = self._evaluator.project.sys_path \
sys_path_mod = self._evaluator.get_sys_path() \
+ sys_path.check_sys_path_modifications(self.module_context)
if self.file_path is not None:
# If you edit e.g. gunicorn, there will be imports like this:
@@ -459,7 +459,7 @@ class Importer(object):
def _load_module(evaluator, path=None, code=None, sys_path=None, parent_module=None):
if sys_path is None:
sys_path = evaluator.project.sys_path
sys_path = evaluator.get_sys_path()
dotted_path = path and dotted_from_fs_path(path, sys_path)
if path is not None and path.endswith(('.py', '.zip', '.egg')) \
@@ -519,7 +519,9 @@ def get_modules_containing_name(evaluator, modules, name):
if name in code:
module = _load_module(evaluator, path, code)
module_name = sys_path.dotted_path_in_sys_path(evaluator.project.sys_path, path)
module_name = sys_path.dotted_path_in_sys_path(
evaluator.get_sys_path(), path
)
if module_name is not None:
add_module(evaluator, module_name, module)
return module

View File

@@ -130,7 +130,7 @@ def check_sys_path_modifications(module_context):
def sys_path_with_modifications(evaluator, module_context):
return evaluator.project.sys_path + check_sys_path_modifications(module_context)
return evaluator.get_sys_path() + check_sys_path_modifications(module_context)
def detect_additional_paths(evaluator, script_path):