linux-cultist / venv-selector.nvim

Allows selection of python virtual environment from within neovim
MIT License
378 stars 40 forks source link

All venv in one dir #108

Closed steakhutzeee closed 1 month ago

steakhutzeee commented 3 months ago

Hi, given the scenario where all venvs are in $HOME/.venv how should we configure the plugin?

I tried to set path as $HOME/.venv, parents to 0.But nothing is found.

I tried to set path to $HOME, parents to 0 and name to .venv but then the list will include every subdir of $HOME/.venv.

Is it possible to only list the "single" venvs and avoid "duplicates" ?

The structure is like:

$HOME/.venv/:

Thanks!

mdic commented 2 months ago

I have a similar situation, whereby all my venv folders are contained in one main venvs folder, with each being contained in a subfolder beginning with the following pattern:

venv_

as such I've tried using a regex pattern in the plugin config file, but to no avail - I'm not a Lua/nvim expert, and yet I have tried many different regex styles and none worked. Any suggestion on how to make the plugin recognise each venv_ folder as one venv, and listing only each main folder? Thanks in advance

linux-cultist commented 2 months ago

Hey,

The plugin cant do this right now actually. It always wants to know the name of the venv to search for, and in this scenario you need it to be more dynamic (every folder under a certain path).

Since the plugin was created, it has changed so much to try and support more and more scenarios, and the code is getting a bit messy now and hard to understand.

Im experimenting with a new version of the plugin where the entire search is much more configurable by the user. I will write more about it if Im happy with how its working out. :)

linux-cultist commented 2 months ago

The new version I'm working on is under the regexp branch. It's not done yet, but if you want, you can try it out and see if you can write a fd command to list the python virtual environments you are interested in.

If you can list the virtual environments using fd on the command line, you can put that straight into the plugin config as well and it will work. There are a few examples how to configure in the Readme under the regexp branch. You can also look in the config.lua file to see how the plugin looks for venv manager plugins and get inspired by the regexp used there.

linux-cultist commented 1 month ago

I just tried and the regexp branch of the plugin can easily do this.

This fd command will list your venvs: fd 'python$' ~/.venv

/home/cado/.venv/venv1/bin/python
/home/cado/.venv/venv2/bin/python
/home/cado/.venv/venv3/bin/python

Add the fd command to your plugin configuration:


      require("venv-selector").setup {
        settings = {
          search = {
            my_venvs = {
              command = "fd 'python$' ~/.venv",
            },
          },
        },
      }

And they will show up in the telescope viewer.

image

Please note that in order to actually activate the venv so you get code completion, a python file must be opened so the LSP is running in neovim.

linux-cultist commented 1 month ago

Closing this since it should work fine in regexp version of the plugin. Reopen if it doesn't or if you have questions. :)