mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 19:50:38 +00:00
48 lines
937 B
Lua
48 lines
937 B
Lua
function CheckPoetryVirtualEnv()
|
|
local poetry = vim.fn.system("poetry env info -p 2>/dev/null")
|
|
if poetry == "" then
|
|
return nil
|
|
end
|
|
return poetry
|
|
end
|
|
|
|
function ResolvePythonEnvironment()
|
|
-- Check if asdf is installed
|
|
|
|
-- Get system global python env
|
|
local python = vim.fn.system("which python3")
|
|
-- Check of virtual environments exists
|
|
local virtual = os.getenv("VIRTUAL_ENV") or CheckPoetryVirtualEnv()
|
|
|
|
if virtual == nil then
|
|
return {
|
|
"--python-executable",
|
|
python,
|
|
}
|
|
end
|
|
|
|
return {
|
|
"--python-executable",
|
|
virtual .. "/bin/python",
|
|
}
|
|
end
|
|
|
|
function ResolvePythonEnvironmentAsString()
|
|
local env = ResolvePythonEnvironment()
|
|
if env == nil then
|
|
return ""
|
|
end
|
|
|
|
local path = table.concat(env, " ")
|
|
|
|
return path
|
|
end
|
|
|
|
M = {}
|
|
|
|
M.ResolvePythonEnvironmentAsString = ResolvePythonEnvironmentAsString
|
|
M.ResolvePythonEnvironment = ResolvePythonEnvironment
|
|
M.CheckPoetryVirtualEnv = CheckPoetryVirtualEnv
|
|
|
|
return M
|