From e516a9e4b7d2729e20a75daec848f783cd35bca2 Mon Sep 17 00:00:00 2001 From: Inhyuk Cho Date: Mon, 17 Jun 2024 04:30:13 +0000 Subject: [PATCH 1/3] fix: prefer stock python --- lua/mason-core/installer/managers/pypi.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/mason-core/installer/managers/pypi.lua b/lua/mason-core/installer/managers/pypi.lua index e9d54559f..c6bcfd183 100644 --- a/lua/mason-core/installer/managers/pypi.lua +++ b/lua/mason-core/installer/managers/pypi.lua @@ -85,8 +85,10 @@ local function create_venv(pkg) -- 2. Resolve suitable versioned python3 installation (python3.12, python3.11, etc.). local versioned_candidates = {} if supported_python_versions ~= nil then - log.fmt_debug("Finding versioned candidates for %s", supported_python_versions) - versioned_candidates = get_versioned_candidates(supported_python_versions) + if stock_target and not pep440_check_version(tostring(stock_target.version), supported_python_versions) then + log.fmt_debug("Finding versioned candidates for %s", supported_python_versions) + versioned_candidates = get_versioned_candidates(supported_python_versions) + end end local target = resolve_python3(versioned_candidates) or stock_target From ff9288e22938dd8d29e8018d4e15e5c69ed36e6c Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 9 Jul 2024 14:45:01 +0200 Subject: [PATCH 2/3] add test --- .../installer/managers/pypi_spec.lua | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index 2bd1f9759..2c59d0566 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -179,6 +179,39 @@ describe("pypi manager", function() end ) + it( + "should prioritize stock python", + function() + local ctx = create_dummy_context { force = true } + spy.on(ctx.stdio_sink, "stderr") + stub(ctx, "promote_cwd") + stub(ctx.fs, "file_exists") + stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8")) + stub(vim.fn, "executable") + vim.fn.executable.on_call_with("python3.12").returns(1) + stub(spawn, "python3", mockx.returns(Result.success())) + spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.8.0" }) + + installer.exec_in_context(ctx, function() + pypi.init { + package = { name = "cmake-language-server", version = "0.1.10" }, + upgrade_pip = true, + install_extra_args = { "--proxy", "http://localhost" }, + } + end) + + assert.spy(ctx.promote_cwd).was_called(1) + assert.spy(ctx.spawn.python3).was_called(1) + assert.spy(ctx.spawn["python3.12"]).was_called(0) + assert.spy(ctx.spawn.python3).was_called_with { + "-m", + "venv", + "--system-site-packages", + "venv", + } + end + ) + it("should install", function() local ctx = create_dummy_context() stub(ctx.fs, "file_exists") From 4945ac4dfd6fa6e933ca4a9e7f540d3196ab58db Mon Sep 17 00:00:00 2001 From: William Boman Date: Tue, 9 Jul 2024 14:45:46 +0200 Subject: [PATCH 3/3] style --- .../installer/managers/pypi_spec.lua | 57 +++++++++---------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index 2c59d0566..6689e3502 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -179,38 +179,35 @@ describe("pypi manager", function() end ) - it( - "should prioritize stock python", - function() - local ctx = create_dummy_context { force = true } - spy.on(ctx.stdio_sink, "stderr") - stub(ctx, "promote_cwd") - stub(ctx.fs, "file_exists") - stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8")) - stub(vim.fn, "executable") - vim.fn.executable.on_call_with("python3.12").returns(1) - stub(spawn, "python3", mockx.returns(Result.success())) - spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.8.0" }) - - installer.exec_in_context(ctx, function() - pypi.init { - package = { name = "cmake-language-server", version = "0.1.10" }, - upgrade_pip = true, - install_extra_args = { "--proxy", "http://localhost" }, - } - end) + it("should prioritize stock python", function() + local ctx = create_dummy_context { force = true } + spy.on(ctx.stdio_sink, "stderr") + stub(ctx, "promote_cwd") + stub(ctx.fs, "file_exists") + stub(providers.pypi, "get_supported_python_versions", mockx.returns(Result.success ">=3.8")) + stub(vim.fn, "executable") + vim.fn.executable.on_call_with("python3.12").returns(1) + stub(spawn, "python3", mockx.returns(Result.success())) + spawn.python3.on_call_with({ "--version" }).returns(Result.success { stdout = "Python 3.8.0" }) - assert.spy(ctx.promote_cwd).was_called(1) - assert.spy(ctx.spawn.python3).was_called(1) - assert.spy(ctx.spawn["python3.12"]).was_called(0) - assert.spy(ctx.spawn.python3).was_called_with { - "-m", - "venv", - "--system-site-packages", - "venv", + installer.exec_in_context(ctx, function() + pypi.init { + package = { name = "cmake-language-server", version = "0.1.10" }, + upgrade_pip = true, + install_extra_args = { "--proxy", "http://localhost" }, } - end - ) + end) + + assert.spy(ctx.promote_cwd).was_called(1) + assert.spy(ctx.spawn.python3).was_called(1) + assert.spy(ctx.spawn["python3.12"]).was_called(0) + assert.spy(ctx.spawn.python3).was_called_with { + "-m", + "venv", + "--system-site-packages", + "venv", + } + end) it("should install", function() local ctx = create_dummy_context()