1
0
forked from VimPlug/jedi

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

@@ -1,4 +1,8 @@
import os
from glob import glob
import sys
import pytest
from jedi._compatibility import unicode
from jedi.parser import Parser, load_grammar
@@ -19,13 +23,30 @@ def test_paths_from_assignment():
assert paths('sys.path, other = ["a"], 2') == []
def test_get_sys_path(monkeypatch):
monkeypatch.setenv('VIRTUAL_ENV', os.path.join(os.path.dirname(__file__),
'egg-link', 'venv'))
def sitepackages_dir(venv):
return os.path.join(venv, 'lib', 'python3.4', 'site-packages')
# Currently venv site-packages resolution only seeks pythonX.Y/site-packages
# that belong to the same version as the interpreter to avoid issues with
# cross-version imports. "venvs/" dir contains "venv27" and "venv34" that
# mimic venvs created for py2.7 and py3.4 respectively. If test runner is
# invoked with one of those versions, the test below will be run for the
# matching directory.
CUR_DIR = os.path.dirname(__file__)
VENVS = list(glob(os.path.join(CUR_DIR,
'venvs/venv%d%d' % sys.version_info[:2])))
monkeypatch.setattr('jedi.evaluate.sys_path._get_venv_sitepackages',
sitepackages_dir)
assert '/path/from/egg-link' in sys_path.get_sys_path()
@pytest.mark.parametrize('venv', VENVS)
def test_get_venv_path(venv):
pjoin = os.path.join
venv_path = sys_path.get_venv_path(venv)
site_pkgs = (glob(pjoin(venv, 'lib', 'python*', 'site-packages')) +
glob(pjoin(venv, 'lib', 'site-packages')))[0]
ETALON = [
site_pkgs,
pjoin(site_pkgs, '.', 'relative', 'egg-link', 'path'),
pjoin('/path', 'from', 'egg-link'),
pjoin(site_pkgs, 'dir-from-foo-pth'),
pjoin('/path', 'from', 'smth.py'),
pjoin('/path', 'from', 'smth.py:extend_path')
]
assert venv_path[:len(ETALON)] == ETALON