Skip to content

Support for virtualenv #6

Open
Open

Description

@ribtoks

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

Activity

  1. brentyi commented on Jul 25, 2023

    @brentyi
    Owner

    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.

  2. ribtoks commented on Jul 25, 2023

    @ribtoks
    Author

    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.

  3. brentyi commented on Jul 30, 2023

    @brentyi
    Owner

    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.

  4. ribtoks commented on Aug 3, 2023

    @ribtoks
    Author

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions