linux-cultist / venv-selector.nvim

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

add support for passing in venv #86

Closed Jobin-Nelson closed 1 month ago

Jobin-Nelson commented 6 months ago

This is a feature request to support passing in venv path manually like :VenvSelect ./.venv

I have my poetry configured to create venv inside the project itself. But it creates .venv which venv-selector is not detecting. Instead of supporting detection of every virtualenv folders out there can we have a way to manually pass in a venv folder to select it.

linux-cultist commented 6 months ago

Hi,

You can configure VenvSelector to look for .venv as a name. It can also look for many names at the same time. The Readme has more info about the options.

And you can set the path option to look in a specific place all the time, and if you do, make sure to set parents to 0 also so it doesn't look in parent folders to that path.

But yes, could be an idea to let users set the path dynamically without using the config options. In some cases it could be nice.

Jobin-Nelson commented 6 months ago

Yes I agree too. This approach would be straight forward if we already know which venv to activate

Doekeb commented 4 months ago

Just came across this situation. I have a workspace where the virtual environment is installed in a non-standard directory name. Rather than adding that name to all the search paths, I'd like to just manually provide the path once and cache the virtual environment.

linux-cultist commented 2 months ago

This is simple to do in the new version of the plugin I'm working on in the regexp branch. If you want you can check it out, and if you write a fd command to pick up the venvs, you can just put it in the plugin config. See the readme for an example how to add your own search.

It's still under heavy development but you can test it and give feedback. I expect the new version to be done in a few weeks.

linux-cultist commented 1 month ago

I didnt go for this exact solution in the regexp branch, since the new VenvSelect will find any venvs in your current directory and below. You dont have to specify a name to search for - it will find all pythons and their full paths.

If you want to search outside of your current directory, you can easily add a search for that as well yourself.

The new version also remembers what venv you have activated before for each directory, and will automatically activate it the next time you open a python file in that directory.

The end result is that for a given project under some path, your selected venv will be activated automatically and you dont have to think about it anymore.

If you want to try it out:

Configuration for lazy.nvim:

return {
  "linux-cultist/venv-selector.nvim",
    dependencies = {
      "neovim/nvim-lspconfig", 
      "mfussenegger/nvim-dap", "mfussenegger/nvim-dap-python", --optional
      { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } },
    },
  lazy = false,
  branch = "regexp", -- This is the regexp branch, use this until its merged with the main branch later
  config = function()
      require("venv-selector").setup()
    end,
    keys = {
      { ",v", "<cmd>VenvSelect<cr>" },
    },
},

Make sure to read through the README for the regexp branch since it works in a very different way now, and old options no longer apply.

linux-cultist commented 1 month ago

Closing this for now since the new regexp branch works in similar ways. Give it a try please. :)