You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's customary to use Python tools in Neovim from their own virtualenv so that it does not clutter the main system. Currently this plugin does not allow for such customization.
e.g. Neovim allows to set Python with let g:python3_host_prog = $HOME . '/.virtualenvs/nvim/bin/python3' and Black has a proper support for this
What's the desired configuration / behavior you have in mind?
Does appending the virtual environment to your PATH variable solve this, eg via let $PATH = $HOME . '/.virtualenvs/nvim/bin:' . $PATH, or via vim.env in Lua? Or are you saying we should auto-detect when g:python3_host_prog is set?
To me a tricky thing with the latter is that projects can have pinned isort versions, so it doesn't necessarily make sense to prioritize a copy of isort that's available in an nvim environment over a copy of isort in a project-specific environment.
As a side note, sandboxed isort installs made via Mason should work out of the box.
Desired configuration would be to have the same behavior as Black so that when I set g:python3_host_prog, isort.vim would automatically resolve path to isort itself (just like Black resolves path to black). Regarding pinned isort, if there's a "local" pinned isort, it can be used - I thought this should work automatically because usually if there's a pinned isort, there's already some sort of local virtualenv?
I use Vim Plug, so Mason tip would not work for me, but thank you for the suggestion.
Ok! I'm still trying to figure out what the logic is for selecting which isort executable to use that would result in the behavior you want.
Do you have an example from another plugin? I checked the official Black one and couldn't find anything about g:python3_host_prog specifically. The way we do things right now also seems to match what plugins like vim-codefmt do for black and other formatters.
I use Vim Plug, so Mason tip would not work for me, but thank you for the suggestion.
There's not actually any incompatibility here; you would install mason.nvim via vim-plug. But perhaps that's separate from this particular issue.
python3_host_prog defines Python environment for Neovim as a whole. If I run in my Neovim: :py3 print(sys.exec_prefix), the output is ~/.virtualenvs/my-nvim-virtualenv. Now if you look at Black plugin for vim here, we are using this sys.exec_prefix which just resolves to virtualenv python (and, naturally, virtualenv pip) and the whole other Black's logic will already use correct python binary.
Activity
brentyi commentedon Jul 25, 2023
Hi, thanks for the issue!
What's the desired configuration / behavior you have in mind?
Does appending the virtual environment to your
PATHvariable solve this, eg vialet $PATH = $HOME . '/.virtualenvs/nvim/bin:' . $PATH, or viavim.envin Lua? Or are you saying we should auto-detect wheng:python3_host_progis set?To me a tricky thing with the latter is that projects can have pinned isort versions, so it doesn't necessarily make sense to prioritize a copy of
isortthat's available in annvimenvironment over a copy ofisortin a project-specific environment.As a side note, sandboxed
isortinstalls made via Mason should work out of the box.ribtoks commentedon Jul 25, 2023
Thank you for fast reply!
Desired configuration would be to have the same behavior as Black so that when I set
g:python3_host_prog, isort.vim would automatically resolve path toisortitself (just like Black resolves path toblack). Regarding pinned isort, if there's a "local" pinned isort, it can be used - I thought this should work automatically because usually if there's a pinned isort, there's already some sort of local virtualenv?I use Vim Plug, so Mason tip would not work for me, but thank you for the suggestion.
brentyi commentedon Jul 30, 2023
Ok! I'm still trying to figure out what the logic is for selecting which
isortexecutable to use that would result in the behavior you want.Do you have an example from another plugin? I checked the official Black one and couldn't find anything about
g:python3_host_progspecifically. The way we do things right now also seems to match what plugins likevim-codefmtdo forblackand other formatters.There's not actually any incompatibility here; you would install
mason.nvimviavim-plug. But perhaps that's separate from this particular issue.ribtoks commentedon Aug 3, 2023
python3_host_progdefines Python environment for Neovim as a whole. If I run in my Neovim::py3 print(sys.exec_prefix), the output is~/.virtualenvs/my-nvim-virtualenv. Now if you look at Black plugin for vim here, we are using thissys.exec_prefixwhich just resolves to virtualenvpython(and, naturally, virtualenvpip) and the whole other Black's logic will already use correct python binary.