Conversation
| end | ||
|
|
||
| local get_poetry_venvs_base_path = function() | ||
| local which_poetry = io.popen('which poetry') |
There was a problem hiding this comment.
I'm starting to get a bit worried about performance when all these functions are called and some call out to external executables. I don't use it but some users use the auto_venv which calls this on FileType. I wonder if this should be done async. This is somewhat independent from this PR but something I thought of now.
I also wonder, the current implementation supports the venvs_path setting. Would it be an option to support that being a function and instead supply this as a optional utility function which a user can use instead of the default venvs_path?
There was a problem hiding this comment.
Whell, i will replace sys calls this with parametrs in plugin config.
There was a problem hiding this comment.
I realized that poetry support does not require any code mutation. I can just use venvs_path.
But I'm still thinking. which is useful to replace venvs_path with venvs_paths, with one, two or many directories.
There was a problem hiding this comment.
Also i can set use "has_conda" 'has_pixi', 'has_micromama' param. If it set to false - functions will not be called.
Like this:
if settings.spec_envs == nil then
return venvs
end
if 'conda' in setting.spec_envs then
vim.list_extend(venvs, get_venvs_for(get_conda_base_path(), 'conda'))
vim.list_extend(venvs, get_conda_base_env())
endThis will speed up the plugin a bit, but... at the cost of backward compatibility.
It may be worth making a separate branch for such a change. For example, 'nightly_speedup'.
There was a problem hiding this comment.
In the meantime, I agree - everything except the usual venus should be handled asynchronously.
There was a problem hiding this comment.
But I'm still thinking. which is useful to replace venvs_path with venvs_paths, with one, two or many directories.
Yeah I think that would be useful, maybe just support the setting to be string, table or function returning string or table? This could then be backwards compatible.
Also i can set use "has_conda" 'has_pixi', 'has_micromama' param. If it set to false - functions will not be called.
Like this:
I think that's a good idea, maybe it can default to true for now to be backwards compatible and then at least it can be disabled if speed is an issue?
|
Wouldn't it be easier to change https://github.com/AckslD/swenv.nvim/blob/main/lua/swenv/api.lua#L200 : from: M.auto_venv = function()
-- the function tries to activate in-project venvs, if present. Otherwise it tries to activate a venv in venvs folder
-- which best matches the project name.
local loaded, project_nvim = pcall(require, 'project_nvim.project')
local venvs = settings.get_venvs(settings.venvs_path)
if not loaded then
print('Error: failed to load the project_nvim.project module')
return
end
local project_dir, _ = project_nvim.get_project_root()
if project_dir then -- project_nvim.get_project_root might not always return a project path
local venv_name = read_venv_name_in_project(project_dir)
if venv_name then
local venv = { path = get_local_venv_path(project_dir), name = venv_name }
set_venv(venv)
return
end
venv_name = read_venv_name_common_dir(project_dir)
if venv_name then
local venv = best_match(venvs, venv_name)
if venv then
set_venv(venv)
return
end
end
end
endto: M.auto_venv = function()
-- Check if the $VIRTUAL_ENV environment variable exists
local virtual_env = os.getenv("VIRTUAL_ENV")
if virtual_env then
-- Extract the last part of the $VIRTUAL_ENV path
local venv_name = virtual_env:match("([^/]+)$")
if venv_name then
local venv = { path = virtual_env, name = venv_name }
set_venv(venv)
return
end
end
-- The function tries to activate in-project venvs, if present. Otherwise it tries to activate a venv in venvs folder
-- which best matches the project name.
local loaded, project_nvim = pcall(require, 'project_nvim.project')
local venvs = settings.get_venvs(settings.venvs_path)
if not loaded then
print('Error: failed to load the project_nvim.project module')
return
end
local project_dir, _ = project_nvim.get_project_root()
if project_dir then -- project_nvim.get_project_root might not always return a project path
local venv_name = read_venv_name_in_project(project_dir)
if venv_name then
local venv = { path = get_local_venv_path(project_dir), name = venv_name }
set_venv(venv)
return
end
venv_name = read_venv_name_common_dir(project_dir)
if venv_name then
local venv = best_match(venvs, venv_name)
if venv then
set_venv(venv)
return
end
end
end
end |
|
Basically using $VIRTUAL_ENV |
|
@aemonge hmm, but wouldn't that only work if you already had the venv activated? I don't actually use the |
|
You're right ! |
No description provided.