mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Cleanup SameEnvironment and use the same logic for creation in virtualenvs
This commit is contained in:
@@ -153,9 +153,9 @@ def _get_virtual_env_from_var():
|
|||||||
variable is considered to be safe / controlled by the user solely.
|
variable is considered to be safe / controlled by the user solely.
|
||||||
"""
|
"""
|
||||||
var = os.environ.get('VIRTUAL_ENV')
|
var = os.environ.get('VIRTUAL_ENV')
|
||||||
if var is not None:
|
if var:
|
||||||
if var == sys.prefix:
|
if var == sys.prefix:
|
||||||
return SameEnvironment()
|
return _try_get_same_env()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return create_environment(var, safe=False)
|
return create_environment(var, safe=False)
|
||||||
@@ -184,6 +184,10 @@ def get_default_environment():
|
|||||||
if virtual_env is not None:
|
if virtual_env is not None:
|
||||||
return virtual_env
|
return virtual_env
|
||||||
|
|
||||||
|
return _try_get_same_env()
|
||||||
|
|
||||||
|
|
||||||
|
def _try_get_same_env():
|
||||||
env = SameEnvironment()
|
env = SameEnvironment()
|
||||||
if not os.path.basename(env.executable).lower().startswith('python'):
|
if not os.path.basename(env.executable).lower().startswith('python'):
|
||||||
# This tries to counter issues with embedding. In some cases (e.g.
|
# This tries to counter issues with embedding. In some cases (e.g.
|
||||||
|
|||||||
@@ -131,11 +131,13 @@ def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch)
|
|||||||
assert env.path == 'fake'
|
assert env.path == 'fake'
|
||||||
|
|
||||||
|
|
||||||
def test_get_default_environment_when_embedded(monkeypatch):
|
@pytest.mark.parametrize('virtualenv', ['', 'fufuuuuu', sys.prefix])
|
||||||
|
def test_get_default_environment_when_embedded(monkeypatch, virtualenv):
|
||||||
# When using Python embedded, sometimes the executable is not a Python
|
# When using Python embedded, sometimes the executable is not a Python
|
||||||
# executable.
|
# executable.
|
||||||
executable_name = 'RANDOM_EXE'
|
executable_name = 'RANDOM_EXE'
|
||||||
monkeypatch.setattr(sys, 'executable', executable_name)
|
monkeypatch.setattr(sys, 'executable', executable_name)
|
||||||
|
monkeypatch.setenv('VIRTUAL_ENV', virtualenv)
|
||||||
env = get_default_environment()
|
env = get_default_environment()
|
||||||
assert env.executable != executable_name
|
assert env.executable != executable_name
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user