-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry support #35
base: main
Are you sure you want to change the base?
Poetry support #35
Conversation
@@ -139,6 +139,24 @@ local get_micromamba_base_path = function() | |||
end | |||
end | |||
|
|||
local get_poetry_venvs_base_path = function() | |||
local which_poetry = io.popen('which poetry') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whell, i will replace sys calls this with parametrs in plugin config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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())
end
This 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime, I agree - everything except the usual venus should be handled asynchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened #36 for the async part
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
end to: 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.