linux-cultist / venv-selector.nvim

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

Compatibility with pyenv-virtualenv #18

Closed GordianDziwis closed 1 year ago

GordianDziwis commented 1 year ago

pyenv-virtualenv saves the venvs under their name in a central place: e.g.

/foo/env1
/foo/env2

Workaround for now ist to add the env names to the name var name = { 'ckan', '.venv', },

One solution would be to allow regex/glob in the path specification.

IceS2 commented 1 year ago

Hey! I've got the same issue to be honest... Been trying to craft a handmade solution for the time being but I'm pretty bad with Lua :rofl:

This is the closest I've come:

return {
  "linux-cultist/venv-selector.nvim",
  dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim" },
  event = "VeryLazy",
  config = function()
    local venv_path = "$PYENV_ROOT/versions/" -- Not sure $PYENV_ROOT gets expanded, I hardcoded mine

    local s = vim.fn.system("ls " .. venv_path)
    local result = {}

    for line in s:gmatch("[^\n]+") do
      if not (line:find("3", 1, true) == 1) then
        table.insert(result, line)
      end
    end

    require("venv-selector").setup {
      search_venv_managers = false,
      search_workspaces = true,
      search = true,
      parents = 0,
      path = venv_path,
      name = result,
      fd_binary_name = "fd"
    }
  end
}

But even then, since I'm searching for the name in subfolders I get a messy prompt... At least I'm able to filter the prompt and pick the right one

linux-cultist commented 1 year ago

It would be nice to properly support pyenv-virtualenv also. It would be a quick addition since we can literally just use the same code as when checking for Poetry and Pipenv venvs.

So this we should do. I can look into it next weekend if I have time.

linux-cultist commented 1 year ago

Im very happy to see a PR for this already! And with some luck, we can merge it in tomorrow. :)