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
Merged

Virtualenv changes #806

merged 12 commits into from
May 9, 2018

Conversation

davidhalter
Copy link
Owner

@davidhalter davidhalter commented Apr 17, 2018

This is mostly needed, because we are now using jedi 0.12.0.

Most of the changes are minor. The bigger one is that force_py_version now just affects the environment version (which is a lot better and works better). You cannot choose between VIM's Python 2/3 anymore.

I think that a more interesting thing will be to use jedi.find_virtualenvs and jedi.find_system_environments. Users should then be allowed to switch to those. But that's material for another pull request and just a new feature. Plus I'm not even sure that I'm going to do that.

This basically corrupts VIM's Python, because it might be having a differnet prefix (Python 3.6) than sys path. I don't know who came up with this - probably it's just how Python loads venvs - but it's definitely not good. Fortunately we can just reset it and be happy.
@davidhalter
Copy link
Owner Author

Tests are failing. I will investigate soon.

@davidhalter
Copy link
Owner Author

It's working now. I forgot to merge... :) Can you please review and merge @blueyed? It fixes the :JediDebugInfo command among other things.

Copy link
Collaborator

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Will test it tomorrow.

except AttributeError:
# Somehow sys.prefix is set in combination with VIM and virtualenvs.
# However the sys path is not affected. Just reset it to the normal value.
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this needed for? (in the case of not AttributeError)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Bad documentation. Sorry. It's at least somewhat better, now.

global last_force_python_error

force_python_version = vim_eval("g:jedi#force_py_version")
environment = jedi.api.environment.get_cached_default_environment()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could be skipped with != "auto" - only needed in case on an exception then.

Copy link
Owner Author

@davidhalter davidhalter Apr 25, 2018

Choose a reason for hiding this comment

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

I changed it in a slightly different way.

def get_environment():
global last_force_python_error

force_python_version = vim_eval("g:jedi#force_py_version")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could optionally become a buffer-local variable, so that you could use different versions per buffer then.
vim_eval("get(b:, 'jedi_force_py_version', get(g:, 'jedi#force_py_version')")

Copy link
Owner Author

Choose a reason for hiding this comment

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

I agree. I just think that this should be part of another pull request.

- cache current environment
- s/jedi.get_python_environment/jedi.get_system_environment: the former
  does not exist (renamed in davidhalter/jedi@336087f)
- improve error display
Copy link
Collaborator

@blueyed blueyed left a comment

Choose a reason for hiding this comment

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

Pushed a fixup / improvement already.
The following review was pending.

doc/jedi-vim.txt Outdated
will be used for every jedi call to the respective python interpreter.
The variable can be set in the .vimrc like this to force python 3:
If you have installed multiple Python versions, you can force the Python
version that is going to be used. To ensure that jedi environments are used.
Copy link
Collaborator

Choose a reason for hiding this comment

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

To ensure that jedi environments are used.

?

Copy link
Collaborator

Choose a reason for hiding this comment

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

s/python/Python/g

Same for Jedi?

doc/jedi-vim.txt Outdated

or set directly using this function, which has the same name as the variable:
Function: `jedi#force_py_version(py_version)`
This variable can be switched during runtime.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Having/keeping a function would allow for validation and completion(s) (via a command), but I assume the validation happens on usage then.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Checked that - but currently it would fail over and over again (but not display the error).
I think the Environment should be cached altogether, will add that.

Copy link
Owner Author

@davidhalter davidhalter May 5, 2018

Choose a reason for hiding this comment

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

I don't understand. What is failing? It probably shouldn't (if it's Jedi, it's even more serious).

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.

@davidhalter
Copy link
Owner Author

I added two comments, you probably have to show those (Show outdated).

@davidhalter davidhalter merged commit 6781eb1 into master May 9, 2018
@davidhalter
Copy link
Owner Author

I merged now, because I probably fixed the remaining issues and not merging it caused JediDebugInfo to not work.

I'm happy to do further changes if they are necessary.

@davidhalter davidhalter deleted the virtualenv branch July 4, 2018 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants