mirror of
https://github.com/boxpositron/absolute-vim.git
synced 2026-02-28 11:40:36 +00:00
feat(lua): add utility functions to detect Lua, OS, Python environment, TypeScript environment, Git root, and safe function invocation.
This commit is contained in:
47
lua/absolute/utils/detect-python-env.lua
Normal file
47
lua/absolute/utils/detect-python-env.lua
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
Reference in New Issue
Block a user