mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-20 20:41:13 +08:00
This commit is contained in:
@@ -189,8 +189,16 @@ def get_default_environment():
|
|||||||
return SameEnvironment()
|
return SameEnvironment()
|
||||||
|
|
||||||
|
|
||||||
@time_cache(seconds=10 * 60) # 10 Minutes
|
|
||||||
def get_cached_default_environment():
|
def get_cached_default_environment():
|
||||||
|
environment = _get_cached_default_environment()
|
||||||
|
if environment.path != os.environ.get('VIRTUAL_ENV'):
|
||||||
|
_get_cached_default_environment.clear_cache()
|
||||||
|
return _get_cached_default_environment()
|
||||||
|
return environment
|
||||||
|
|
||||||
|
|
||||||
|
@time_cache(seconds=10 * 60) # 10 Minutes
|
||||||
|
def _get_cached_default_environment():
|
||||||
return get_default_environment()
|
return get_default_environment()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ def time_cache(seconds):
|
|||||||
|
|
||||||
wrapper.clear_cache = lambda: cache.clear()
|
wrapper.clear_cache = lambda: cache.clear()
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import jedi
|
|||||||
from jedi._compatibility import py_version
|
from jedi._compatibility import py_version
|
||||||
from jedi.api.environment import get_default_environment, find_virtualenvs, \
|
from jedi.api.environment import get_default_environment, find_virtualenvs, \
|
||||||
InvalidPythonEnvironment, find_system_environments, \
|
InvalidPythonEnvironment, find_system_environments, \
|
||||||
get_system_environment, create_environment
|
get_system_environment, create_environment, get_cached_default_environment
|
||||||
|
|
||||||
|
|
||||||
def test_sys_path():
|
def test_sys_path():
|
||||||
@@ -129,3 +129,10 @@ def test_get_default_environment_from_env_does_not_use_safe(tmpdir, monkeypatch)
|
|||||||
monkeypatch.setenv('VIRTUAL_ENV', fake_python)
|
monkeypatch.setenv('VIRTUAL_ENV', fake_python)
|
||||||
env = get_default_environment()
|
env = get_default_environment()
|
||||||
assert env.path == 'fake'
|
assert env.path == 'fake'
|
||||||
|
|
||||||
|
|
||||||
|
def test_changing_venv(venv_path, monkeypatch):
|
||||||
|
monkeypatch.setitem(os.environ, 'VIRTUAL_ENV', venv_path)
|
||||||
|
get_cached_default_environment()
|
||||||
|
monkeypatch.setitem(os.environ, 'VIRTUAL_ENV', sys.executable)
|
||||||
|
assert get_cached_default_environment().executable == sys.executable
|
||||||
|
|||||||
Reference in New Issue
Block a user