junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
34.03k stars 1.93k forks source link

Installing Python dependencies at plugin install time? #949

Open Erotemic opened 4 years ago

Erotemic commented 4 years ago

I'm working on a plugin that requires third party Python packages at runtime, and I was wondering if there was a standard way to have these dependencies installed at plugin install time? If not, is that something that vim-plug might be able to support?

For references the plugin I'm working on is here: https://github.com/Erotemic/vimtk

I'm not 100% that I'm doing everything correctly when it comes to creating a vim plugin. I've read several tutorials and used a lot of Tim Pope's code as a guideline, but I still don't feel that I have a fantastic grasp on best practices. In addition to this question, if anyone has any resources they could point me to so I can step up my vim-plugin game, I would greatly appreciate it. I'm especially interested in any forums or message boards where I might be able to get help / code reviews.

janlazo commented 4 years ago

Use a post-install hook, https://github.com/junegunn/vim-plug#post-update-hooks. Pass a function reference to do for more control. If there are Vimscript parsing issues because of Plug command, call plug#() directly.

There's no standard for managing plugin dependencies. You have to come up with your own method (ie. autoload?) and when to install/update/cleanup (ie VimEnter, VimLeave).

Erotemic commented 3 years ago

That feeling when you google a question and the top result is a question you wrote almost a year ago. :weary:

It looks like jedi doesn't have a great solution for this either. Just switched my main python interpreter and now my plugin can't find any pip packages.

I had a python section in my vimrc that read:

# Define Python2or3
if has('python3')
    command! -nargs=1 Python2or3 python3 <args>
elseif has('python')
    command! -nargs=1 Python2or3 python <args>
else
    echo "Error: Requires Vim compiled with +python or +python3"
    finish
endif
# End Define Python2or3

Python2or3 << endpython3
import vim
import sys
print(sys.version_info)
print(sys.prefix)
print(sys.executable)
endpython3

And I got this result:

sys.version_info(major=3, minor=8, micro=5, releaselevel='final', serial=0)
/home/joncrall/.pyenv/versions/3.9.2/envs/py39
/home/joncrall/.pyenv/versions/3.9.2/envs/py39/bin/python3

I was using pyenv to use a 3.9 python environment, but I guess vim was compiled with 3.8.5. But then prefix and executable got loaded from python 3.9 somehow? I just want a way to ensure that any Python dependencies on pypi used by my plugin are available to that plugin.

I suppose I could use a post install hook to do something custom, but I also want to make it easy for people who install my plugin. I'd also like to not mess with sys.path if possible, but maybe I need to.

EDIT:

I think I diagnosed some of it. Part of the issue had to do with something I don't fully understand of how vim links to python. The result was when vim invokes the python interpreter there are some python symbols that aren't included because they aren't used in vim. However, they are needed when running subsequent modules that you install. Adding export LDFLAGS="-rdynamic" before I compile a custom vim against a custom pyenv python got me past one blocking point. There are still more.

See https://github.com/ycm-core/YouCompleteMe/issues/3760 for some details.