ncm2 / ncm2-jedi

MIT License
23 stars 11 forks source link

jedi._compatibility.which('python') may always return the path of python2 #18

Closed xrayw closed 5 years ago

xrayw commented 5 years ago

I found the error on Mac,

In [2]: jedi._compatibility.which('python')
Out[2]: '/usr/bin/python'

In [3]: jedi._compatibility.which('python3')
Out[3]: '/usr/local/bin/python3'
xrayw commented 5 years ago

But I just tested it on Mac, Need some test on Windows and Linux.

xrayw commented 5 years ago

On windows, usually named python, instead of python3. 😅

xrayw commented 5 years ago

Now I'm use the code

sys.platform.lower() == 'darwin'

to determine mac platform and only change on Mac.

roxma commented 5 years ago

Could you try jedi.get_default_environment()? I prefer jedi.get_default_environment if it works for you.

xrayw commented 5 years ago

But the option 'ncm2_jedi#python_version' could invalid when using jedi.get_default_environment() ??

roxma commented 5 years ago

But the option 'ncm2_jedi#python_version' could invalid when using jedi.get_default_environment() ??

ncm2_jedi#python_version only decides the python2/python3 process that runs jedi.

Unfortunately this causes some confusion. But It is not designed to decide target completion version.

However, My local test shows that when running python2, jedi.get_default_environment() gets python2, when running python3, it gets python3. I'm not sure how much ncm2_jedi#python_version affects jedi library behavior. Therefore I left ncm2_jedi#python_version configurable.

xrayw commented 5 years ago

En.... But how about the pull request? pull request #16

roxma commented 5 years ago

@UzimakiNaruto Thanks for pointing it out. I forgot that change there.

@Guzzii I think #16 should be revered,

16

When a virtual env or conda env is activated, its python executable path is placed to the first position in $PATH.

Since jedi doc says that jedi.get_default_environment() handles virtualenv automatically.

jedi.get_default_environment()[source] Tries to return an active Virtualenv. If there is no VIRTUAL_ENV variable set it will return the latest Python version installed on the system. This makes it possible to use as many new Python features as possible when using autocompletion and other functionality.

I'm not sure how it goes with conda. But since we have many types of environment and there's no way to generalize, it's a better idea to stick to jedi's default. Use g:ncm2_jedi#environment for customization.

Guzzii commented 5 years ago

@roxma I agree. Users can always rely on g:ncm2_jedi#environment to set the python executable. It is true even after #16.

@UzimakiNaruto raised a valid point. With #16, it wouldn't pick up python executable named by explicit version. However, the reason why jedi._compatibility.which('python') didn't return /usr/local/bin/python3 is because /usr/local/bin/python3 was installed by Homebrew, which is a not environment manager, and as a result has to rely on explicit name to differentiate. I feel like in these type of situations, g:ncm2_jedi#environment is the answer.

roxma commented 5 years ago

Please test #19

xrayw commented 5 years ago

It works fine for me.