linux-cultist / venv-selector.nvim

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

Use pyrightconfig.json if it's in the project root #90

Closed kuator closed 1 month ago

kuator commented 6 months ago

Pyright and Pylance have a pyrightconfig.json which can be used to determine venv location. Sample pyrightconfig.json

{
  "venvPath": "/home/doka/.local/share/virtualenvs",
  "venv": "c142fad17f39dbb53c07810005e5f4eaaf81369e"
}
linux-cultist commented 5 months ago

Yes, but this plugin is for switching between venvs dynamically. But maybe you are suggesting that the plugin would pick up whatever is in pyrightconfig.json if its in the current working directory?

kuator commented 5 months ago

Yes, but this plugin is for switching between venvs dynamically. But maybe you are suggesting that the plugin would pick up whatever is in pyrightconfig.json if its in the current working directory?

Yes. pyrgithtconfig.json file is located at the root of the project most of the time, that's why picking up virtual environment for it would make sense, in my opinion

linux-cultist commented 1 month ago

I went for a slightly different solution here, but one that i think works equally well.

VenvSelect in the regexp branch remembers what python you have picked for each working directory, and activates it automatically the next time you open a python file in that directory.

I felt this was a better solution since its not depending on parsing any files, and it will work for any lsp, not just pyright.

If you want to give it a try, here is some instructions for the new branch:

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>" },
    },
},
linux-cultist commented 1 month ago

Closing this since regexp branch will remember the activated venv for a specific directory. Please try it. :)

kuator commented 1 month ago

Closing this since regexp branch will remember the activated venv for a specific directory. Please try it. :)

Thank, will do