-
-
Notifications
You must be signed in to change notification settings - Fork 370
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
Virtualenv changes #806
Conversation
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.
Tests are failing. I will investigate soon. |
It's working now. I forgot to merge... :) Can you please review and merge @blueyed? It fixes the :JediDebugInfo command among other things. |
There was a problem hiding this 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.
pythonx/jedi_vim.py
Outdated
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
pythonx/jedi_vim.py
Outdated
global last_force_python_error | ||
|
||
force_python_version = vim_eval("g:jedi#force_py_version") | ||
environment = jedi.api.environment.get_cached_default_environment() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
pythonx/jedi_vim.py
Outdated
def get_environment(): | ||
global last_force_python_error | ||
|
||
force_python_version = vim_eval("g:jedi#force_py_version") |
There was a problem hiding this comment.
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')")
There was a problem hiding this comment.
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
There was a problem hiding this 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. |
There was a problem hiding this comment.
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.
?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
pythonx/jedi_vim.py
Outdated
environment = None | ||
if force_python_version != "auto": | ||
if vim_force_python_version == "auto": | ||
environment = jedi.api.environment.get_cached_default_environment() |
There was a problem hiding this comment.
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.
I added two comments, you probably have to show those ( |
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. |
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.