Skip to content

Commit bce96d2

Browse files
authored
feat: don't use vim.g.python3_host_prog as a candidate for python (#1606)
This is inconsistent with how other system dependencies are resolved and is not documented anywhere.
1 parent c7e6705 commit bce96d2

File tree

4 files changed

+2
-68
lines changed

4 files changed

+2
-68
lines changed

lua/mason-core/installer/managers/pypi.lua

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,7 @@ function M.init(opts)
7272

7373
a.scheduler()
7474

75-
local executables = platform.is.win
76-
and _.list_not_nil(
77-
vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog),
78-
"python",
79-
"python3"
80-
)
81-
or _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python3", "python")
75+
local executables = platform.is.win and { "python", "python3" } or { "python3", "python" }
8276

8377
-- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path.
8478
ctx:promote_cwd()

lua/mason-core/managers/pip3/init.lua

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ function M.install(packages)
4848

4949
a.scheduler()
5050

51-
local executables = platform.is.win
52-
and _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python", "python3")
53-
or _.list_not_nil(vim.g.python3_host_prog and vim.fn.expand(vim.g.python3_host_prog), "python3", "python")
51+
local executables = platform.is.win and { "python", "python3" } or { "python3", "python" }
5452

5553
-- pip3 will hardcode the full path to venv executables, so we need to promote cwd to make sure pip uses the final destination path.
5654
ctx:promote_cwd()

lua/mason/health.lua

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,6 @@ local function check_languages()
280280
}
281281
end
282282
end,
283-
function()
284-
a.scheduler()
285-
if vim.g.python3_host_prog then
286-
check {
287-
cmd = vim.fn.expand(vim.g.python3_host_prog),
288-
args = { "--version" },
289-
name = "python3_host_prog",
290-
relaxed = true,
291-
}
292-
a.scheduler()
293-
check {
294-
cmd = vim.fn.expand(vim.g.python3_host_prog),
295-
args = { "-m", "pip", "--version" },
296-
name = "python3_host_prog pip",
297-
relaxed = true,
298-
}
299-
end
300-
end,
301283
}
302284
end
303285

tests/mason-core/managers/pip3_spec.lua

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -63,61 +63,21 @@ describe("pip3 manager", function()
6363
it(
6464
"should exhaust python3 executable candidates if all fail",
6565
async_test(function()
66-
vim.g.python3_host_prog = "/my/python3"
6766
local handle = InstallHandleGenerator "dummy"
6867
local ctx = InstallContextGenerator(handle)
6968
ctx.spawn.python3 = spy.new(mockx.throws())
7069
ctx.spawn.python = spy.new(mockx.throws())
71-
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.throws())
7270
local err = assert.has_error(function()
7371
installer.prepare_installer(ctx):get_or_throw()
7472
installer.exec_in_context(ctx, pip3.packages { "package" })
7573
end)
76-
vim.g.python3_host_prog = nil
7774

7875
assert.equals("Unable to create python3 venv environment.", err)
79-
assert.spy(ctx.spawn["/my/python3"]).was_called(1)
8076
assert.spy(ctx.spawn.python3).was_called(1)
8177
assert.spy(ctx.spawn.python).was_called(1)
8278
end)
8379
)
8480

85-
it(
86-
"should not exhaust python3 executable if one succeeds",
87-
async_test(function()
88-
vim.g.python3_host_prog = "/my/python3"
89-
local handle = InstallHandleGenerator "dummy"
90-
local ctx = InstallContextGenerator(handle)
91-
ctx.spawn.python3 = spy.new(mockx.throws())
92-
ctx.spawn.python = spy.new(mockx.returns {})
93-
ctx.spawn[vim.g.python3_host_prog] = spy.new(mockx.returns {})
94-
95-
installer.prepare_installer(ctx):get_or_throw()
96-
installer.exec_in_context(ctx, pip3.packages { "package" })
97-
vim.g.python3_host_prog = nil
98-
assert.spy(ctx.spawn.python3).was_called(0)
99-
assert.spy(ctx.spawn.python).was_called(1)
100-
assert.spy(ctx.spawn["/my/python3"]).was_called(1)
101-
end)
102-
)
103-
104-
it(
105-
"should expand python3_host_prog path",
106-
async_test(function()
107-
vim.g.python3_host_prog = "~/python3"
108-
local handle = InstallHandleGenerator "dummy"
109-
local ctx = InstallContextGenerator(handle)
110-
ctx.spawn.python = spy.new(mockx.returns {})
111-
ctx.spawn[vim.env.HOME .. "/python3"] = spy.new(mockx.returns {})
112-
113-
installer.prepare_installer(ctx):get_or_throw()
114-
installer.exec_in_context(ctx, pip3.packages { "package" })
115-
a.scheduler()
116-
vim.g.python3_host_prog = nil
117-
assert.spy(ctx.spawn[vim.env.HOME .. "/python3"]).was_called(1)
118-
end)
119-
)
120-
12181
it(
12282
"should use install_args from settings",
12383
async_test(function()

0 commit comments

Comments
 (0)