Improve virtualenv support & egg-link resolution

- add sys_path= kwarg to Script & Evaluator constructors

- store sys_path for each evaluator instance

- replace get_sys_path with get_venv_path

- get_venv_path: use addsitedir to load .pth extension files

- get_venv_path: look for egg-link files in all directories in path
This commit is contained in:
immerrr
2015-04-05 00:19:11 +02:00
parent 3eaa3b954a
commit 4eb3cf7921
20 changed files with 174 additions and 86 deletions

View File

@@ -61,6 +61,7 @@ that are not used are just being ignored.
"""
import copy
import sys
from itertools import chain
from jedi.parser import tree
@@ -79,7 +80,7 @@ from jedi.evaluate import helpers
class Evaluator(object):
def __init__(self, grammar):
def __init__(self, grammar, sys_path=None):
self.grammar = grammar
self.memoize_cache = {} # for memoize decorators
# To memorize modules -> equals `sys.modules`.
@@ -88,6 +89,13 @@ class Evaluator(object):
self.recursion_detector = recursion.RecursionDetector()
self.execution_recursion_detector = recursion.ExecutionRecursionDetector()
self.analysis = []
if sys_path is None:
sys_path = sys.path
self.sys_path = copy.copy(sys_path)
try:
self.sys_path.remove('')
except ValueError:
pass
def wrap(self, element):
if isinstance(element, tree.Class):