-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinterpreters.lua
More file actions
81 lines (76 loc) · 2.48 KB
/
Copy pathinterpreters.lua
File metadata and controls
81 lines (76 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
local PythonVENVInterpreters = {}
local IS_WINDOWS = vim.uv.os_uname().sysname == "Windows_NT"
local IS_MACOS = vim.uv.os_uname().sysname == "Darwin"
---
---@return table found_hatch_pythons list of python interpreters found by hatch
function PythonVENVInterpreters.hatch_interpreters()
if vim.fn.executable("hatch") == 1 then
local hatch_python_paths = vim.fn.expand("~/.local/share/hatch/pythons")
if vim.fn.isdirectory(hatch_python_paths) then
local found_hatch_pythons =
vim.fn.globpath(hatch_python_paths, vim.fs.joinpath("**", "bin", "python3.*"), false, true)
if found_hatch_pythons then
return found_hatch_pythons
end
end
end
return {}
end
---
---@return table found_uv_pythons list of python interpreters found by uv
function PythonVENVInterpreters.uv_interpreters()
if vim.fn.executable("uv") == 1 then
local uv_python_paths = vim.fn.expand("~/.local/share/uv/python")
if vim.fn.isdirectory(uv_python_paths) then
local found_uv_pythons = vim.fn.globpath(uv_python_paths, vim.fs.joinpath("**", "bin", "python3.*"), false, true)
if found_uv_pythons then
return found_uv_pythons
end
end
end
return {}
end
---@return table<string> list of potential python interpreters to use
function PythonVENVInterpreters.python_interpreters()
-- TODO detect python interpreters from windows
if IS_WINDOWS then
return { "python3" }
end
local pythons = vim.fn.globpath("/usr/bin/", "python3.*", false, true)
if IS_MACOS then
local homebrew_path = vim.fn.globpath("/opt/homebrew/bin/", "python3.*", false, true)
for _, p in pairs(homebrew_path) do
table.insert(pythons, 1, p)
end
end
local found_uv = PythonVENVInterpreters.uv_interpreters()
if found_uv then
for _, p in pairs(found_uv) do
table.insert(pythons, 1, p)
end
end
local found_hatch = PythonVENVInterpreters.hatch_interpreters()
if found_hatch then
for _, p in pairs(found_hatch) do
table.insert(pythons, 1, p)
end
end
local interpreters = nil
for _, p in pairs(pythons) do
if not interpreters then
interpreters = {}
end
if string.match(vim.fs.basename(p), "python3.%d+$") then
table.insert(interpreters, 1, p)
end
end
if not interpreters then
vim.notify_once(
"python.nvim: Warning could not detect python interpreters. Defaulting to python3",
vim.log.levels.WARN
)
interpreters = { "python3" }
end
return interpreters
end
return PythonVENVInterpreters