AckslD / swenv.nvim

Tiny plugin to quickly switch python virtual environments from within neovim without restarting.
206 stars 29 forks source link

Specify Virtualenv when using multiple different venv tools. #19

Closed fxdgear closed 9 months ago

fxdgear commented 11 months ago

Sometimes the venv is created through virtualenv sometimes it's created through poetry and sometimes it's created through pipenv and hell who knows I might even used pyenv one day.

IF I need to specify lots of different locations for venvs, how can I tell lunarvim where to look for all of em?

AckslD commented 11 months ago

@fxdgear swenv currently assumes that all your venvs is in a single folder. You can however provide your own get_venvs function to the setup.

fxdgear commented 11 months ago

Could you help advise me on a function that could do that?

I’m not a lua guy and I’m not sure how to debug it when running in lunarvim.

skolj commented 11 months ago

@fxdgear you could extend the default get_venvs function in your config to add more sources for venvs. For example:

require('swenv').setup({

  -- other options
  venvs_path = vim.fn.expand('~/venvs'),

  get_venvs = function (venvs_path)
    local venvs = require('swenv.api').get_venvs()

    local more_venvs = {}

    local scan_dir = require('plenary.scandir').scan_dir

    -- Another venv source
    local paths = scan_dir('/path/to/another/venvs/dir', { depth = 1, only_dirs = true, silent = true })
    for _, path in ipairs(paths) do
      table.insert(more_venvs, {
        name = 'venv name',
        path = path,
        source = '<source name>',
      })
    end

    return vim.tbl_deep_extend("keep", venvs, more_venvs)
  end
})

You could also change the venvs_path option to return a list of sources and change the get_venvs implementation.

fxdgear commented 11 months ago

Thank you!! I’ll get to playing with this!!