Giter VIP home page Giter VIP logo

venv-selector.nvim's People

Contributors

11d-beyonder avatar avivelmakias1 avatar belyakov-am avatar dddyom avatar ices2 avatar jo-project avatar joinemm avatar leitec avatar linux-cultist avatar lvignoli avatar mdietrich16 avatar mehalter avatar mennohofste avatar mgua avatar mpaliwoda avatar mrgreentea avatar neolooong avatar petobens avatar qizidog avatar rubenduburck avatar sped0n avatar stewart86 avatar svitax avatar tianyouzeng avatar ulthuan avatar yysfire avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

venv-selector.nvim's Issues

Support for spaces in venv paths

Hatch is popular python project manager that takes care of virtual environments as well.

Could vent-selector also search into the default location for hatch?

Any type of environment that is not explicitly defined will default to <DATA_DIR>/env/<ENV_TYPE>. (see there)

can't find local venv - bad fdfind arguments

Hi! Thank you for this project :)
Plugin can't find my local venv

VenvSelect: 
{
  anaconda_path = "$CONDA_PREFIX/envs",
  auto_refresh = false,
  cache_dir = "/home/user/.cache/venv-selector/",
  cache_file = "/home/user/.cache/venv-selector/venvs.json",
  changed_venv_hooks = { <function 1>, <function 2> },
  dap_enabled = false,
  enable_debug_output = true,
  hatch_path = "~/.local/share/hatch/env/virtual",
  name = { "env", "venv", ".venv" },
  notify_user_on_activate = true,
  parents = 2,
  pipenv_path = "~/.local/share/virtualenvs",
  poetry_path = "~/.cache/pypoetry/virtualenvs",
  pyenv_path = "~/.pyenv/versions",
  search = true,
  search_venv_managers = true,
  search_workspace = true,
  venvwrapper_path = "$HOME/.virtualenvs"
}
VenvSelect: Setting fd_binary_name to 'fdfind' since it was found on system instead of fd.
VenvSelect: Telescope path: /home/user/projects/project1/project2/src/apps/web
VenvSelect: Refresh telescope since there are no previous results.
VenvSelect: Removed telescope results.
VenvSelect: Finding parent venvs in: /home/user/projects/project1/project2/src
VenvSelect: Found workspace folder: /home/user/projects/project1/project2
VenvSelect: Running search for workspace venvs with: fdfind -HItd --absolute-path --color never '(^env$|^venv$|^.venv$)' --full-path /home/user/projects/project1/project2 
VenvSelect: Running search for venv manager venvs with: fdfind . -HItd -tl --absolute-path --max-depth 1 --color never --full-path /home/user/.cache/pypoetry/virtualenvs --full-path /home/user/.pyenv/versions 
VenvSelect: Found venv in VenvManager search: /home/user/.cache/pypoetry/virtualenvs/ddtrt-dqZtyGoo-py3.10
VenvSelect: Found venv in VenvManager search: /home/user/.pyenv/versions/3.11.0
VenvSelect: There are 2 results to show:
VenvSelect: 
{ {
    icon = "",
    path = "/home/user/.cache/pypoetry/virtualenvs/dsj2102-dqZtyGoo-py3.10"
  }, {
    icon = "",
    path = "/home/user/.pyenv/versions/3.11.0"
  } }

The problem I think lies in

fdfind -HItd --absolute-path --color never '(^env$|^venv$|^.venv$)' --full-path /home/user/projects/project1/project2

This returns nothing. But this does:

fdfind -HItd --absolute-path --color never '(^env$|^venv$|^.venv$)' /home/user/projects/project1/project2

Removed --full-path.

Best regards.

Miniconda support? (python.exe in venv root directory, not scripts or bin)

First off thanks for a sweet plugin!

That said, I was trying to use it with a mini-conda environment and ran into an issue where my python.exe executables are housed in the root venv directory.

For example:
.../Miniconda3/envs/my_env_name/python.exe

The anaconda { python_parent_dir = nil } option only let's one pick /Scripts or /bin, neither of which apply in a Miniconda case. The default is Scripts as I'm sure your aware.

Any chance you can create an option like anaconda { python_parent_dir = 'root' }?

I am a lua beginner, but I may give it a shot if I can figure it out.

Thanks!

Setting multiple `name`s returns too many results

The configuration examples note the following about the name configuration option:

NOTE: You can also use a lua table here for multiple names: {"venv", ".venv"}`

When using the following settings, the result set in the telescope window includes all files/dirs in the current directory:

  {
    "linux-cultist/venv-selector.nvim",
    opts = {
      search_venv_managers = false,
      search_workspace = true,
      search = true,
      name = { "venv", ".venv" },
    },
  },

Enforce `poetry env use` when having multiple env

In my GIF I have two environments with poetry, one with python 3.10 and another one with 3.11. If I then

  1. Run poetry env list from a terminal I see that the currently activated venv is 3.10.
  2. Run :VenvSelect and choose the 3.11 environment
  3. Re open a terminal and re-run poetry env list -> poetry still sees 3.10 as the active environment.

So I guess that what's missing is to run poetry env use <env> during activation of an environment.

poetry-venv

I am working on windows, my venvs are folders like venv_XXXX where XXXX can change.

I would like to be able to use wildcards in specifying the env list in name={"venv","venv_*"}

if anyway I hardcode my venvname there, I get an error apparently related to missing write privileges on a folder which appears writable.

E5108: Error executing lua Vim:E482: Can't open file %APPDATA%\venv-selector\venvs.json for writing: no such file or directory
stack traceback:
        [C]: in function 'writefile'
        ...-data/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:303: in function 'cache_venv'
        ...-data/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:207: in function 'activate_venv'
        .../lazy/venv-selector.nvim/lua/venv-selector/telescope.lua:76: in function 'key_func'
        ...nvim-data/lazy/telescope.nvim/lua/telescope/mappings.lua:352: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk
Press ENTER or type command to continue```

Any hints?

fd command not working in Ubuntu distro

Context

OS: Windows 11 running WSL2 Ubuntu 22.04
Default Shell set with chsh: Fish
Neovim version: 0.8
Plugin manager: Lazy
Configuration used: according to README.md guide for Lazy
requirements installed:
fd: yes (using apt install fd-find)
telescope: yes

Expected behaviour

Using mapped key (<leader>vs) should show telescope with a list of virtualenvs to pick from.

Actual behvaiour

after keying <leader>vs nothing happened.

Investigate

After some debugging, realised that vim.loop.spawn() is using the sh shell to execute the fd command. As I am using Ubuntu, according to fd guide there is a conflict with another binary in the distro, so alias was suggested to be use. As a result, I have set alias for bash shell and fish shell. But vime.loop.spwan() is not using either one.

turn out I changed the command from fd to fdfind and it works as expected.

Proposal

Allow a config variable to change fd to fdfind or find depends on user preference.

Changed Server Capabilities are not preserved upon `VenvSelect`

Thanks for this nice plugin, just stumbled upon it by chance!

So I am using pyright and pylsp at the same time, and I use this snippet to disable pyright's hover capabilities, since I prefer pylsp's:

require("lspconfig").pyright.setup {
  on_attach = function(client, _) client.server_capabilities.hoverProvider = false end
}

However, it seems that the way this plugin sets up the LSPs, only the settings are carried over, but not the disabled server capabilities, meaning that as soon as I use VenvSelect, the hover capability is re-enabled again.

(I tried various versions of updating the lsp config via hooks or simply using local on_attach = vim.deepcopy(pyright.config.on_attach) to preserve the disabled hover, but could not make it work.)

Not actually calling `fdfind`

Greetings,

I love the concept of this plugin and desperately want to get it working (I think it worked once!). It seems to me that when I run VenvSelect or use my keybind <leader>vs, I see an empty Telescope pop up. If I turn on VenvSelect debugging, I no longer see the Telescope pop up. Regardless of debugging status, when looking at tools like top and htop, I never see fdfind being run as a result of using VenvSelect.

Here is my current plugin config:

return {
  "linux-cultist/venv-selector.nvim",
  opts = {
    auto_refresh = true,
    fd_binary_name = "fdfind",
    name = "venvtest",
    dap_enabled = true,
    path = "~/workspace",
    parents = 1,
    enable_debug_output = true,
    search_venv_managers = false,
    search_workspace = false,
    search = true
  }
}

I have a test Python venv created as follows: python3 -m venv ~/venvtest

I'm working on a project in the following path: /home/ben/workspace/kiewit/ansible/playbooks/ap_linux_instance

Here is the VenvSelect debugging when running the VenvSelect command:

VenvSelect: 
{
  anaconda = {},
  anaconda_base_path = "",
  anaconda_envs_path = "/home/ben/.conda/envs",
  auto_refresh = true,
  cache_dir = "/home/ben/.cache/venv-selector/",
  cache_file = "/home/ben/.cache/venv-selector/venvs.json",
  changed_venv_hooks = { <function 1>, <function 2>, <function 3> },
  dap_enabled = true,
  enable_debug_output = true,
  fd_binary_name = "fdfind",
  hatch_path = "~/.local/share/hatch/env/virtual",
  name = "venvtest",
  notify_user_on_activate = true,
  parents = 1,
  path = "~/workspace",
  pipenv_path = "~/.local/share/virtualenvs",
  poetry_path = "~/.cache/pypoetry/virtualenvs",
  pyenv_path = "~/.pyenv/versions",
  search = true,
  search_venv_managers = false,
  search_workspace = false,
  venvwrapper_path = "~/.virtualenvs"
}
VenvSelect: Setting fd binary to 'fdfind' since it was found on system and requested by user instead of fd.
VenvSelect: Using path from settings path: ~/workspace
VenvSelect: Looking for parent venvs in '~' using the following parameters:
VenvSelect: 
{ "--absolute-path", "--color", "never", "-E", "/proc", "-HItd", "^venvtest$", "~" }
VenvSelect: There are 0 results to show.

This all happens very fast (almost too fast IMHO), I see no fdfind activity in top/htop.

However, if manually run fdfind as follows:

time fdfind --absolute-path --color "never" -E "/proc" -HItd "(^venvtest)" ~
/home/ben/venvtest

real    0m20.835s
user    0m9.728s
sys     0m17.971s

I get the result I expect and it does take some time (I also see several parallel fdfind processes in top/htop).

Any idea what I'm doing wrong here? I'm using neovim v0.9.2 using a customized/tuned LazyVim.org configuration, running on Ubuntu 22.04 with fd 8.3.1 (installed as fdfind).

Cannot find correct Python execution path under Miniconda with empty string for anaconda python_parent_dir

Hi,

Thank you for sharing such a great and convenient plugin for us. Unfortunately I had difficulty to use it correctly under my Ubuntu 20.04 and miniconda. Here is my configuration in LazyVim:

return {
  "linux-cultist/venv-selector.nvim",
  dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim", "mfussenegger/nvim-dap-python" },
  opt = {
    enable_debug_output = true,
    dap_enabled = true, -- Enable DAP integration.
    anaconda = { python_parent_dir = "" },
    anaconda_base_path = "~/miniconda3",
    anaconda_envs_paths = "~/miniconda3/envs",
    search = false,
  },
  keys = {
    -- Keymap to open VenvSelector to pick a venv.
    { "<leader>vs", "<cmd>VenvSelect<cr>" },
    -- Keymap to retrieve the venv from a cache (the one previously used for the same project directory).
    { "<leader>vc", "<cmd>VenvSelectCached<cr>" },
  },
}

However, the miniconda paths that venv-selector found is incorrect, which is shown in following screenshots:
venu-selector
屏幕截图 2023-11-23 180138

The real python interpreter path should be inside .../Miniconda3/envs/my_env_name/python.exe, even although I already set anaconda = { python_parent_dir = "" } but i do not understand why there is still extra folder path /lib/python3.7/venv after anaconda_envs_paths. Meanwhile I also set enable_debug_output = true, to print debug info. Unfortunately when I type `:messages' still I cannot find any debug info. Is there anything incorrect for my setting?

Sorry for my configuration question as a new Lua and Neovim user.

Best,
Leihan

Support/configuration for virtualenvwrapper?

I have been trying to configure the plugin using the following configuration,

require("venv-selector").setup({
    auto_refresh = true,
    search_venv_managers = false,
    path = "/custom_home_dir/user/.virtualenvs", -- $WORKON_HOME absolute path where virtualenvwrapper creates venvs
    name = {"venv", ".venv", "site-packages"}, -- I added site-packages because the other dirs won't be there
})

I am using virtualenvwrapper so commands like workon VENV and deactivate are supported via the command line. But with this configuration it is not able to find my venvs located under the specificied path. Instead it also searches through all the venvs in other user's home directories which I found was unexpected.

I could only find documentation for the other venv managers like pyenv-virtualenv which I migrated away from as it didn't let me run python with gdb because of shims. If you could guide me on how to configure this virtualenvwrapper that would be great!

`search = false` not returning valid results

The configuration examples note the following about the search configuration option:

If you only use venvs located in project folders, you can set search = false and search_workspace = true.

and

You can set this to false to speed up the plugin if your virtual envs are in your workspace, or in Poetry or Pipenv locations. No need to search if you know where they will be.

Yet, the following configuration returns no results:

  {
    "linux-cultist/venv-selector.nvim",
    opts = {
      search_venv_managers = false,
      search_workspace = true,
      search = false,
      name = ".venv",
    },
  },

If I set search to true, the results appear, but are not exclusive to the workspace anymore.

Anyway to get venv-selector to look for local python venv

If I have a different python venv in the same directory as the python project how can I show that on venv selector. This is my current config for the plugin:

require("venv-selector").setup({
    name = { "env", "venv", ".venv" },
})

But it doesn't recognize any local python venvs. For clarification I am using the builitin python command to create a python venv by:
python -m venv env

Lsp can only find definitions for the current file

First of all, this plugin is great. I can switch projects and change the environment without exiting nvim, something that I wanted to do for a long time.

Something I noticed while using the plugin is that the "Go to definition" of the LSP only works on the references existing in the file I've activated the virtual environment in. Let's see an example project with the following structure:

venv-test
├── .env
├── main.py
├── my_utilities.py
└── my_module
──── ├── __init__.py
──── └── a.py

The .env folder contains a virtual environment created with python3 -m venv .env just for the purpose of this demonstration. It does not have additional python packages installed.
The contents of the files are the following:

# main.py
from my_utilities import my_func

def main():
   my_func()
# my_utilities.py
from my_module.a import hello

def my_func():
   hello()
# a.py
def hello():
   print("hello")

If I activate the virtual environment in the terminal before opening vim:

source $HOME/venv-test/.env/bin/activate
nvim main.py

I can "Go to definition" to my_func and once there to the definition of hello().

However if I just open vim without the virtual environment:

nvim main.py

And then do a VenvSelect and select the entry with $HOME/venv-test/.env/bin/activate I can go to the definition of my_func but once there, if I "Go to definition" of hello(), the LSP just jumps to the line where hello() is imported, not the a.py file where hello is defined.

If I do the same procedure but open my_utilities.py instead of main.py and do a "Go to definiton" on hello() it takes me to the function definition correctly so it seems it only breaks the "Go to definition" of the files other than the one I activated venv in.

The LSP (pyright) in both cases shows the same "root" in :LspInfo so I don't know what the VenvSelect is doing that it breaks the "Go to definition". This also happens to me with poetry virtual environments.

My plugin configuration is the following (commit 3e6eac9a883654157fdc11dcb65db48db4194127 (from Aug 23th, 2023):

require('venv-selector').setup({
  name = { "venv", ".env" },
  fd_binary_name = "fdfind"
})

Please, do not hesitate to ask if something is missing or not clear. Thank you!

How to suppress error when running autocmd

Using the autocmd in the readme, when I open a file that has no cached virtualenv i get an error reading cache. is there a way to suppress this error and just have it silently check if any cached venv exists?

Why I don't see venv paths?

image image image

This happens when i open a python file after any other?

This happens even when search options are enabled

Maybe we should look for "fdfind" and use it if it exists

Since its called fdfind on Debian based distributions, maybe we should look for this binary and use it if it exists.

Or at least give a helpful error message if fd doesnt exist. I think right now there is only a silent fail if it doesnt exist, which would make Ubuntu users think the plugin doesnt work.

It's possible to set the fd binary to something else in settings but maybe people don't look there and just assume the plugin fails. We should at least give a helpful error message. :)

VenvSelectCached Command is not working

So I am using miniconda for my virtual environments and I have the plugin set up as follows:

{
    "linux-cultist/venv-selector.nvim",
    opts = {
      search = false,
      anaconda_envs_path = os.getenv "HOME" .. "/miniconda3/envs",
      auto_refresh = true,
      -- search_venv_managers = false,
      search_workspace = false,
    },
    keys = { { "<leader>lv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
  },

I cd into my python project and select a virtual environment. But when I come back again to that directory, and run the command VenvSelectCached it throws the error, Not an editor command. However, if I select the virtual environment and then run VenvSelectCached it works fine.

Not sure if I am doing everything correct. I don't know know much lua, but when I was browsing through the functions, (this one), it seems to like, we need to pass cache_file in the opts?

pyright does not respect pyproject.toml defined extraPaths

As mentioned in #10. Opening a new ticket here to keep track of this issue.

Context

For some specific use case where extraPaths is defined in the pyproject.toml (example below). After activating VenvSelect venv, pyright no longer respect the extra paths defined.

pyproject.toml

...

[tool.pyright]
executionenvironments = [
  { root = "", extrapaths = ["layer/"]},
  { root = "my_serverless_app/lambda_functions/", extrapaths = ["layer/"]},
]

...

Investigation

Even when extraPaths is declared in the lspconfig as such.

lspconfig.lua

return function(opts)
  opts.settings = {
    python = {
      analysis = {
        ...
        -- both relative and absolute path doesn't work
        extraPaths = { "layer/", "<absolute>/<path>/layer/" },
      },
    },
  }
  return opts
end

However, when extraPaths is added into venv.lua

venv.lua

-- Hook into lspconfig so we can set the python to use.
M.set_pythonpath = function(python_path)
	lspconfig.pyright.setup({
		before_init = function(_, c)
			c.settings.python.pythonPath = python_path
			c.settings.python.analysis.extraPaths = { "<absolute>/<path>/layer/" }
		end,
	})
end

Also, before activating VenvSelect pyright knows my extra paths but is not aware of the venv paths. Which was reflected with errors to the externally imported packages. As soon as venv is activated, the import errors switched from showing errors to my internal packages and nothing for the external packages.

To Replicate

This particular use case is mainly for building a AWS serverless application where Lambda Functions and Layer live in a separate runtime environment but stay in a single repository.
Of cause there might be other use cases which I am not aware of.
Directory structure looks similar to this.

directory tree

my_serverless_app/
    layer/
        utils.py
        requirements.txt
    lambda_functions/
        function_one/
            main.py
            requirements.txt
pyproject.toml
.git

In normal circumstances main.py in function_one/ folder should import utils.py as such

my_serverless_app/lambda_functions/function_one/main.py

from my_serverless_app.layer import utils

But this will break on AWS Lambda runtime environment because the root directory is not being included into the runtime. So we can only import as such

my_serverless_app/lambda_functions/function_one/main.py

import utils

That means, we need to declare extraPaths in pyproject.toml for pyright to know that we are directly importing from a particular folder.

How to active the python environment?

Hi author,
Thank you for this wonderful plugin, which helps me a lot, but I meet some problems here.
When I trigger the VenvSelect command with the defined keymap, the envs menu will popup, all this is working properly.

image

But when I choose one of the conda env with the <CR> keymap, it will jump to the envs folder without activing the chosen envs, how to fix that?

I am using lazyvim as my config, here is the config related to this plugin.

return {
  "linux-cultist/venv-selector.nvim",
  cmd = "VenvSelect",
  dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim" },
  event = "VeryLazy",
  opts = {
    search = false,
    name = {
      "venv",
      ".venv",
      "env",
      "envs",
      ".env",
    },
    anaconda_base_path = "/Users/vercent/miniconda3",
    anaconda_envs_path = "/Users/vercent/miniconda3/envs",
  },
  keys = { { "<leader>cv", "<cmd>:VenvSelect<cr>", desc = "Select VirtualEnv" } },
}

Use formatting standard for code contributions

I noticed the project has many different indenting styles, and manually indenting/formatting is no fun.

@linux-cultist, How do you feel about adding a .stylua.toml file to make it uniform and easier to work on? Do you have a personal preference that you could add that to the project?

I do not mind any style (or care about tabs vs. spaces), however, I think sticking to one is always nicer to work with. If you have no preference, I think copying a config from the official NeoVim project would probably be safest. The closest project is probably nvim-lspconfig.

What do you think about this?

add support for passing in venv

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.

Error thrown if user is root

In line 90 of system.lua in the function M.get_cache_default_path()

If the user is root and $USER is nil, the correct path should be returned as "/root/.cache/venv-selector/", currently it's throwing an error.

Support lua regular expressions to make VenvSelect more flexible

This idea comes from VenvSelect supporting many different venv managers now and they are all found in similar ways, but not exactly the same.

So it would be good if the plugin would support a more generic way to list files and filter out venvs.

Just an idea at this point.

[Feature request]: Multiple backends for visual picker

I notice that venv-selector only uses Telescope as its visual picker. It would be great if it migrate to something more general, like vim.ui.select, that way, users can choose between different pickers like nui.nvim or fzf-lua.

Automate with cwd

When the current working dir changes, would be a good time to retirve the venv from cache.

Deactivate environment

I see there is a function to activate and cache an environment

M.activate_venv = function()

Is it possible to add a function to deactivate the active enviroment (i.e remove envs and path and clear the cache?). This would be useful to automate activation/deactivation logic within an autocommand.
Thanks!

feature request: support for conda base env

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!

Error on selecting venv

got this when selecting venv

E5108: Error executing lua ...nvim/lazy/venv-selector.nvim/lua/venv-selector/hooks.lua:46: bad argument #1 to '(for generator)' (uv_req expected, got nil)
stack traceback:
        [C]: in function '(for generator)'
        ...nvim/lazy/venv-selector.nvim/lua/venv-selector/hooks.lua:46: in function 'callback'
        ...nvim/lazy/venv-selector.nvim/lua/venv-selector/hooks.lua:17: in function 'execute_for_client'
        ...nvim/lazy/venv-selector.nvim/lua/venv-selector/hooks.lua:40: in function 'hook'
        .../nvim/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:98: in function 'set_venv_and_system_paths'
        .../nvim/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:206: in function 'activate_venv'
        .../lazy/venv-selector.nvim/lua/venv-selector/telescope.lua:76: in function 'key_func'
        ...hare/nvim/lazy/telescope.nvim/lua/telescope/mappings.lua:350: in function 'execute_keymap'
        [string ":lua"]:1: in main chunk

the problem is here

local directories = vim.fs.dir(lib_path)
local site_packages = nil

for filename, _ in directories do
	if utils.starts_with(filename, "python") then
		site_packages = lib_path .. sys.path_sep .. filename .. sys.path_sep .. "site-packages"
	end
end

works fine this way

for filename, _ in vim.fs.dir(lib_path) do
	if utils.starts_with(filename, "python") then
		site_packages = lib_path .. sys.path_sep .. filename .. sys.path_sep .. "site-packages"
	end
end

not experienced with lua, so a little bit mysterious to me

Suggestion: better way to refresh telescope

The border of the telescope will flash whenever refreshing venv.

It seems that you create a new picker instead of refresh the current one.

If the purpose of flashing is the refresh animation, then I think it might be more appropriate to clear the results first and then fill in the new results.

Compatibility with pyenv-virtualenv

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.

add a command to show current selected venv

There are so many venv created by all kind of projects, sometimes user need to check the absolutely path of venv currently used. Maybe it's a good idea to add a command to show current selected venv?

It's ok to add this command by user but I think it's better to be finished in venv-selector.nvim, right?

Support find instead of fd to reduce dependencies

Hello,

First of all thank you for the great plugin. Im using it in two scenarios like on my local machine and on some remote machine. For the first everything works like a charm but if im on a remote machine (via ssh) i get the following error:

Which i believe is because fd is not installed (do not got sudo rights)

Error executing Lua callback: .../nvim/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:171: bad argument #1 to 'spawn' (string expected, got nil)
stack traceback:
        [C]: in function 'spawn'
        .../nvim/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:171: in function 'find_parent_venvs'
        .../nvim/lazy/venv-selector.nvim/lua/venv-selector/venv.lua:41: in function 'load'
        ...azy/venv-selector.nvim/lua/venv-selector/mytelescope.lua:183: in function 'open'
        .../nvim/lazy/venv-selector.nvim/lua/venv-selector/init.lua:48: in function <.../nvim/lazy/venv-selector.nvim/lua/venv-selector/init.lua:47>

I use lazy to install the plugin as follows:

return 	{
		"linux-cultist/venv-selector.nvim",
		dependencies = {
			"neovim/nvim-lspconfig",
			"nvim-telescope/telescope.nvim",
			"mfussenegger/nvim-dap-python",
		},
		opts = {
			dap_enabled = true, -- makes the debugger work with venv
                        anaconda_base_path = "~/miniconda3/",
                        anaconda_envs_path = "~/miniconda3/envs/",
                        parents = 0,
		},
		keys = {
			{
				"<leader>es", ":VenvSelect<CR>",
				desc = "Select Environment",
			},
		},
}

Doesn't detect venv

Hi author,
I am using WSL and try to use this plugin, but it won't detect my virtual environment (venv)

Do you know how to fix it? Thank you!

venv_doesnt_found
Venv_Config

Explore duplicate Python path change

The Python path is changed twice, once by venv.set_pythonpath, and once with the hooks. The set_pythonpath creates an autocommand that changes the config every time a file is loaded. This is spin-off issue of #58.

Hooks: https://github.com/linux-cultist/venv-selector.nvim/blob/main/lua/venv-selector/hooks.lua
venv.set_pythonpath: https://github.com/linux-cultist/venv-selector.nvim/blob/main/lua/venv-selector/venv.lua#L186C1-L213C1

Hooks:

function M.pyright_hook(_, venv_python)
  local clients = vim.lsp.get_active_clients({ name = "pyright" })
  for _, client in ipairs(clients) do
    client.config.settings = vim.tbl_deep_extend("force", client.config.settings, { python = { pythonPath = venv_python } })
    client.notify("workspace/didChangeConfiguration", { settings = nil })
  end
end

venv.set_pythonpath:

-- Hook into lspconfig so we can set the python to use.
function M.set_pythonpath(python_path)
	vim.api.nvim_create_autocmd({ "BufReadPost" }, {
		pattern = { "*.py" },
		callback = function()
			local active_clients = {}
			for _, client in
				ipairs(vim.lsp.get_active_clients({ name = "pyright", bufnr = vim.api.nvim_get_current_buf() }))
			do
				table.insert(active_clients, client)
			end

			for _, client in
				ipairs(vim.lsp.get_active_clients({ name = "pylance", bufnr = vim.api.nvim_get_current_buf() }))
			do
				table.insert(active_clients, client)
			end

			for _, client in ipairs(active_clients) do
				client.config.settings =
					vim.tbl_deep_extend("force", client.config.settings, { python = { pythonPath = python_path } })

				client.notify("workspace/didChangeConfiguration", { settings = nil })
			end
		end,
	})
end

An autocommand runs every time the event is triggered. BufReadPost is ran when starting to edit a new buffer, after reading the file into the buffer, processing modelines. I do not understand why this is here, as pyright should stay active with the last set settings, so resetting every time a new buffer opens seems redundant. It could be overriding other plugins changing the python path as @cmetz wrote.

Even then, only one autocommand is necessary creating a new one every time the venv changes. Maybe there is a way to change an existing autocommand, if it is necessary.

I will experiment a bit to try and understand this better. Any hints or feedback is welcome.

config options in the readme.md needs to be improved

Some discription of options is not complete, just search in README.md

-- search_venv_managers (default: true). Will search for Poetry and Pipenv virtual environments in their
-- default location. If you dont use the default location, you can
search_venv_managers = true,

Additionally, there are some options that are not mentioned in readme, such as

{
  poetry_path = system.get_venv_manager_default_path("Poetry"),
  pipenv_path = system.get_venv_manager_default_path("Pipenv"),
  pyenv_path = system.get_venv_manager_default_path("Pyenv"),
  anaconda_path = system.get_venv_manager_default_path("Anaconda"),
  venvwrapper_path = system.get_venv_manager_default_path("VenvWrapper"),
}

Suggest writing the function of the parameter into config.lua.

Python executable location with Conda on Windows

It looks like with some venv managers, the python.exe executable is put inside the Scripts directory of the .venv, but for me (Conda/Mamba), the python executable is stored in the base venv directory. For example:

C:\Users\ndaman\mambaforge\envs\pickle\python.exe

is where the actual executable is, but it seems that the plugin is looking for it inside of

C:\Users\ndaman\mambaforge\envs\pickle\Scripts\

Is there any way to change where the plugin looks for the python executable? Thanks!

find venv of pyproject by default?

Hi,
Most of my projects use poetry, and it seems that it doesn't detect it's venvs.
Is is possible to add a feature to detect the virtualenvs created by poetry?
I can't figure out how to make this package detect the venvs it's creating.

Can not find conda envs enviroment

This is the part of my neovim config about this plugins

        {"linux-cultist/venv-selector.nvim",
            dependencies = { "neovim/nvim-lspconfig", "nvim-telescope/telescope.nvim", 
                            "mfussenegger/nvim-dap-python","nvim-lua/plenary.nvim" },
            config = function()
                require("venv-selector").setup({
                    fd_binary_name = "find",
                    anaconda_base_path = "/opt/homebrew/Caskroom/miniconda/base",
                    anaconda_envs_path = "/opt/homebrew/Caskroom/miniconda/base/envs",
    
                })
            end,
            event = "VeryLazy", -- Optional: needed only if you want to type `: VenvSelect` without a keymapping
            keys = {{ "<leader>vs", "<cmd>VenvSelect<cr>" },}
        },

And this is my conda env list
image

However, this plugin can not find the environment as follows.
image
I'm looking for your reply! Thank you, sir.

Poetry venvs appearing regardless of `search_venv_managers` setting

As the title notes, setting the search_venv_managers setting to false seems to have no effect on the search results. Poetry environments are included in the results regardless of other options as well. For example, if I use a bogus name value like name = "asdfqwer", the poetry environments still show up.

Some conda paths being incorrectly searched

Thanks for the amazing plugin! As a conda user, I was extremely excited to find this and set it up a couple of weeks ago and it worked great. I had set it up to only find my anaconda environments since I don't use any other virtual environment managers. It was really fast!

However, with the latest update, I am now finding that it takes a few seconds to update in every project directory. I have tried the various config options but nothing seems to fix it. I am 90% sure that this is a problem with me not finding the correct set of config options and so I am writing to ask for help here.

I install the plugin with lazy.nvim like so:

	-- allow selecting conda environments from within neovim
	{
		"linux-cultist/venv-selector.nvim",
		config = true,
		opts = {
			search = false,
                       search_workspace = false,
                       search_venv_managers = false,
		},
	},

and set it up like so:

require("venv-selector").setup({
    anaconda_base_path = "/Users/nmadnani/anaconda",
    anaconda_envs_path = "/Users/nmadnani/anaconda/envs",
})

Here's a video showing how long the telescope view takes to populate and that it's still looking in places where it shouldn't be. Any suggestions will be greatly appreciated.

venv-selector-small.mp4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.