linux-cultist / venv-selector.nvim

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

feature request: support for conda base env #37

Closed naefl closed 10 months ago

naefl commented 1 year ago

Hey!

Thanks for the great plugin. Conda/mamba/... have the concept of a "base" environment. In the scientific software community, usually that's the main environment people use (yes, yes, bad people). Currently this doesn't work with the conda support.

One can hack it to work, with by changing telescope.lua to

M.add_lines = function(lines, source)
    local icon = source == "Workspace" and "" or ""

    for row in lines do
        if row ~= "" then
            dbg("Found venv in " .. source .. " search: " .. row)
            table.insert(M.results, { icon = icon, path = utils.remove_last_slash(row) })
        end
    end
    table.insert(M.results, { icon = "", path = os.getenv("CONDA_PREFIX") })
end

There seems to be no direct mechanism to injecting a single, specific path directly, so not sure where to include this but happy to put up a PR if you point me where to put this properly!

linux-cultist commented 1 year ago

Thank you!

Yeah I'm starting to realize that there is a need for the plugin to be a bit more dynamic. Originally I was just thinking it would support user created venvs but it grew a lot and now there are more and more needs. :)

There is the "path" option you can set, and that will make the plugin look in that folder only for venvs if you also set parents to 0 (so it doesn't look into parent directories). But that is maybe not exactly what you need?

naefl commented 1 year ago

I believe that will still call fd on the path though to search envs within that folder right? What I need is to specify an absolute path that is an env, not contains them, and that to be appended to all the envs that are available for searching through the envs subdirectory of CONDA_PREFIX

conda is structured like this

$CONDA_PREFIX -> this path itself is the base env, i.e. contains lib, bin, include, ... subdirs, this is the default env that is selected if one does not activate an env. $CONDA_PREFIX/envs -> this path is a directory which contains folders, each of which is an env, lib, bin, include, ... subdirs

linux-cultist commented 11 months ago

I started thinking about this a bit again after my kid started doing data science and I had to help him set up conda environments for his computer so he could run jupyter notebooks. Now I know a bit more about conda. :)

So is this what you had in mind?

image

Being able to switch between the base anaconda environment (set by $CONDA_PREFIX) and also the other environments created inside it?

On my system, the base anaconda location ($CONDA_PREFIX) was /opt/anaconda but the other environments i created from inside conda with conda env create ended up under $HOME/.conda.

Making these be found by VenvSelect in the dev version therefore currently requires 2 settings.

naefl commented 11 months ago

Yes! This would be perfect!

linux-cultist commented 10 months ago

Please try the latest version now, should be working!

Check the updated Readme for config, there are two env variables needed now. :)

naefl commented 10 months ago

working beautifully 🥳 thank you!