linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
388 stars 41 forks source link

Support/configuration for virtualenvwrapper? #34

Closed UtkarshKunwar closed 1 year ago

UtkarshKunwar commented 1 year ago

I have been trying to configure the plugin using the following configuration,

require("venv-selector").setup({
    auto_refresh = true,
    search_venv_managers = false,
    path = "/custom_home_dir/user/.virtualenvs", -- $WORKON_HOME absolute path where virtualenvwrapper creates venvs
    name = {"venv", ".venv", "site-packages"}, -- I added site-packages because the other dirs won't be there
})

I am using virtualenvwrapper so commands like workon VENV and deactivate are supported via the command line. But with this configuration it is not able to find my venvs located under the specificied path. Instead it also searches through all the venvs in other user's home directories which I found was unexpected.

I could only find documentation for the other venv managers like pyenv-virtualenv which I migrated away from as it didn't let me run python with gdb because of shims. If you could guide me on how to configure this virtualenvwrapper that would be great!

linux-cultist commented 1 year ago

Hi and sorry for late response, I was on vacation in Italy and just came back :)

I think you may want to add "parents = 0" to your options there if you want VenvSelect to not go up into parent directories and look for venvs. Maybe that should be default - I can see how its confusing that its looking in parent directories when you specify a specific path to search. This should probably be changed so if the user sets a path, parents are also set to 0 by default. :)

But even if you do that, the virtual environments will have different names under the path (the name you give your virtual environment), and wont be found. So I think adding direct support for virtualenvwrapper to VenvSelector is probably a good idea.

Then it will find those environments without any config on your part. I will see what I can do. :)

linux-cultist commented 1 year ago

If you update VenvSelector now to latest version, it should find virtual environments under ~/.virtualenvs and list them.

But you need to change your config so its more like default:

require("venv-selector").setup({
    search_venv_managers = true,
    auto_refresh = true,
    search = false
})

With this config, the search_venv_managers option is true, and it needs to be so VenvSelector can find the managed venvs. Its default set to true so you can also remove that option from your config.

You also dont need path and the name options for your use case. They are used to search for virtual environments that are not managed by a venv manager such as virtualenvwrapper.

The search parameter set to false will make VenvSelector not search at all for venvs that are not managed by a venv manager, which will make the plugin a lot faster for you. But remember to set it to true if you actually want to look for venv folders outside of virtualenvwrapper.

Hope all this works for you!

linux-cultist commented 1 year ago

Closing this, but feel free to comment or reopen if the new code doesn't work for some reason. :)

UtkarshKunwar commented 8 months ago

I'm sorry for not getting back to you sooner, but it seems to work now with your provided configuration.

Another follow-up question is that if I change the virtual environment using this plugin, how do I have it enforce the same on the already open terminal(s)? I am using ToggleTerm but I think that the logic of this post-activate hook would apply to the standard terminal as well. Do you think I should file a separate issue so that the discussion is contained?