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

Support for virtualenv #6

Open
ribtoks opened this issue Jul 25, 2023 · 4 comments
Open

Support for virtualenv #6

ribtoks opened this issue Jul 25, 2023 · 4 comments

Comments

@ribtoks
Copy link

ribtoks commented Jul 25, 2023

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

@brentyi
Copy link
Owner

brentyi commented 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 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.

@ribtoks
Copy link
Author

ribtoks commented 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 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.

@brentyi
Copy link
Owner

brentyi commented Jul 30, 2023

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.

@ribtoks
Copy link
Author

ribtoks commented Aug 3, 2023

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.

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

No branches or pull requests

2 participants