forked from VimPlug/jedi
Try to use the virtual env that was defined in the VIRTUAL_ENV variable, if possible.
This commit is contained in:
@@ -97,6 +97,12 @@ class InterpreterEnvironment(_BaseEnvironment):
|
|||||||
|
|
||||||
|
|
||||||
def get_default_environment():
|
def get_default_environment():
|
||||||
|
virtual_env = os.environ.get('VIRTUAL_ENV')
|
||||||
|
if virtual_env is not None and virtual_env != sys.prefix:
|
||||||
|
try:
|
||||||
|
return create_environment(virtual_env)
|
||||||
|
except InvalidPythonEnvironment:
|
||||||
|
pass
|
||||||
return DefaultEnvironment()
|
return DefaultEnvironment()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from contextlib import contextmanager
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import jedi
|
import jedi
|
||||||
@@ -71,3 +75,21 @@ def test_killed_subprocess(evaluator, Script):
|
|||||||
def_, = Script('str').goto_definitions()
|
def_, = Script('str').goto_definitions()
|
||||||
# Jedi should now work again.
|
# Jedi should now work again.
|
||||||
assert def_.name == 'str'
|
assert def_.name == 'str'
|
||||||
|
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def set_environment_variable(name, value):
|
||||||
|
tmp = os.environ.get(name)
|
||||||
|
try:
|
||||||
|
os.environ[name] = value
|
||||||
|
yield
|
||||||
|
finally:
|
||||||
|
if tmp is None:
|
||||||
|
del os.environ[name]
|
||||||
|
else:
|
||||||
|
os.environ[name] = tmp
|
||||||
|
|
||||||
|
|
||||||
|
def test_virtualenv():
|
||||||
|
with set_environment_variable('VIRTUAL_ENV', '/foo/bar/jedi_baz'):
|
||||||
|
assert get_default_environment()._executable == sys.executable
|
||||||
|
|||||||
Reference in New Issue
Block a user