Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Virtualenv changes #806

Merged
merged 12 commits into from
May 9, 2018
37 changes: 20 additions & 17 deletions pythonx/jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,36 +158,39 @@ def wrapper(*args, **kwargs):
return func_receiver


last_force_python_error = None
current_environment = (None, None)


def get_environment():
global last_force_python_error
def get_environment(use_cache=True):
global current_environment

vim_force_python_version = vim_eval("g:jedi#force_py_version")
if use_cache and vim_force_python_version == current_environment[0]:
return current_environment[1]

force_python_version = vim_eval("g:jedi#force_py_version")
environment = None
if force_python_version != "auto":
if vim_force_python_version == "auto":
environment = jedi.api.environment.get_cached_default_environment()
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cache anyway, we can just use jedi.get_default_environment() instead. It's the official API, this one is kind of hidden and not really public.

else:
force_python_version = vim_force_python_version
if '0000' in force_python_version or '9999' in force_python_version:
# It's probably a float that wasn't shortened.
try:
force_python_version = "{:.1f}".format(float(force_python_version))
except ValueError:
pass

elif isinstance(force_python_version, float):
force_python_version = "{:.1f}".format(force_python_version)

try:
environment = jedi.get_python_environment(force_python_version)
except jedi.InvalidPythonEnvironment:
if last_force_python_error != force_python_version:
vim.command(
'echom "force_python_version=%s is not supported."'
% force_python_version
)
last_force_python_error = force_python_version

if environment is None:
environment = jedi.api.environment.get_cached_default_environment()
environment = jedi.get_system_environment(force_python_version)
except jedi.InvalidPythonEnvironment as exc:
environment = jedi.api.environment.get_cached_default_environment()
echo_highlight(
"force_python_version=%s is not supported: %s - using %s." % (
vim_force_python_version, str(exc), str(environment)))

current_environment = (vim_force_python_version, environment)
return environment


Expand Down
2 changes: 1 addition & 1 deletion pythonx/jedi_vim_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def display_debug_info():
jedi_vim.jedi.__version__))

try:
environment = jedi_vim.get_environment()
environment = jedi_vim.get_environment(use_cache=False)
except AttributeError:
script_evaluator = jedi_vim.jedi.Script('')._evaluator
try:
Expand Down