From 1b6f69a7b034d9f00bad3b968a456b0effd2e4fd Mon Sep 17 00:00:00 2001 From: Silico_Biomancer Date: Thu, 28 Dec 2023 12:38:12 +1300 Subject: [PATCH 1/4] Let python lsps and debuggers access installed packages Currently, installing something like debugpy via Mason installs it to a virtual environment that does not have anything else installed. If you are using a second virtual environment, mason handles things to access installed packages in that environment. However, if you are using the system python, debugpy or lsps don't see any of your installed packages. For debugpy, this means you cannot run your program. This might be the case when you have packages that you almost always want installed, for example pandas. This change fixes this by transparently letting mason python packages see the system packages, assuming no other dependencies have been installed to the venv and overwritten them. I think this has no downsides for a purpose like mason - Although this is bad practise for regular python software projects, because it disguises required dependencies, in the case of Mason we don't care about required dependencies so long as they do exist. --- lua/mason-core/managers/pip3/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/mason-core/managers/pip3/init.lua b/lua/mason-core/managers/pip3/init.lua index 36ad6fc7b..f4755166d 100644 --- a/lua/mason-core/managers/pip3/init.lua +++ b/lua/mason-core/managers/pip3/init.lua @@ -57,7 +57,7 @@ function M.install(packages) -- Find first executable that manages to create venv local executable = _.find_first(function(executable) - return pcall(ctx.spawn[executable], { "-m", "venv", VENV_DIR }) + return pcall(ctx.spawn[executable], { "-m", "venv", "--system-site-packages", VENV_DIR }) end, executables) Optional.of_nilable(executable) From 9a8dba20adac33795ca764550b033e9b2f6305a9 Mon Sep 17 00:00:00 2001 From: bluedrink9 Date: Sun, 7 Jan 2024 16:15:52 +1300 Subject: [PATCH 2/4] Fix: venv install test --- tests/mason-core/managers/pip3_spec.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua index cf7aff9bd..30c25233c 100644 --- a/tests/mason-core/managers/pip3_spec.lua +++ b/tests/mason-core/managers/pip3_spec.lua @@ -40,6 +40,7 @@ describe("pip3 manager", function() assert.spy(ctx.spawn.python3).was_called_with { "-m", "venv", + "--system-site-packages", "venv", } assert.spy(ctx.spawn.python).was_called(1) From 57c8c16e372ba51d74606aff7d8daab189d6453c Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 21 Mar 2024 10:30:51 +0000 Subject: [PATCH 3/4] feat(pypi): include system site packages in venv --- lua/mason-core/installer/managers/pypi.lua | 3 ++- tests/mason-core/installer/managers/pypi_spec.lua | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lua/mason-core/installer/managers/pypi.lua b/lua/mason-core/installer/managers/pypi.lua index 0f3de1fb5..3c305a42a 100644 --- a/lua/mason-core/installer/managers/pypi.lua +++ b/lua/mason-core/installer/managers/pypi.lua @@ -16,7 +16,7 @@ local VENV_DIR = "venv" local function create_venv(py_executables) local ctx = installer.context() return Optional.of_nilable(_.find_first(function(executable) - return ctx.spawn[executable]({ "-m", "venv", VENV_DIR }):is_success() + return ctx.spawn[executable]({ "-m", "venv", "--system-site-packages", VENV_DIR }):is_success() end, py_executables)):ok_or "Failed to create python3 virtual environment." end @@ -57,6 +57,7 @@ local function pip_install(pkgs, extra_args) "pip", "--disable-pip-version-check", "install", + "--ignore-installed", "-U", extra_args or vim.NIL, pkgs, diff --git a/tests/mason-core/installer/managers/pypi_spec.lua b/tests/mason-core/installer/managers/pypi_spec.lua index 353606aa5..85dd4eabe 100644 --- a/tests/mason-core/installer/managers/pypi_spec.lua +++ b/tests/mason-core/installer/managers/pypi_spec.lua @@ -29,6 +29,7 @@ describe("pypi manager", function() assert.spy(ctx.spawn.python3).was_called_with { "-m", "venv", + "--system-site-packages", "venv", } end) @@ -48,6 +49,7 @@ describe("pypi manager", function() assert.spy(ctx.spawn.python3).was_called_with { "-m", "venv", + "--system-site-packages", "venv", } assert.spy(ctx.spawn[venv_py(ctx)]).was_called(1) @@ -56,6 +58,7 @@ describe("pypi manager", function() "pip", "--disable-pip-version-check", "install", + "--ignore-installed", "-U", { "--proxy", "http://localhost" }, { "pip" }, @@ -76,6 +79,7 @@ describe("pypi manager", function() "pip", "--disable-pip-version-check", "install", + "--ignore-installed", "-U", vim.NIL, -- install_extra_args { @@ -115,6 +119,7 @@ describe("pypi manager", function() "pip", "--disable-pip-version-check", "install", + "--ignore-installed", "-U", vim.NIL, -- install_extra_args { @@ -141,6 +146,7 @@ describe("pypi manager", function() "pip", "--disable-pip-version-check", "install", + "--ignore-installed", "-U", { "--proxy", "http://localhost:9000" }, { From 6e35cbd3143de6b57969a144884725044e053a20 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 21 Mar 2024 10:32:11 +0000 Subject: [PATCH 4/4] revert changes to old, deprecated, manager --- lua/mason-core/managers/pip3/init.lua | 2 +- tests/mason-core/managers/pip3_spec.lua | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/mason-core/managers/pip3/init.lua b/lua/mason-core/managers/pip3/init.lua index f4755166d..36ad6fc7b 100644 --- a/lua/mason-core/managers/pip3/init.lua +++ b/lua/mason-core/managers/pip3/init.lua @@ -57,7 +57,7 @@ function M.install(packages) -- Find first executable that manages to create venv local executable = _.find_first(function(executable) - return pcall(ctx.spawn[executable], { "-m", "venv", "--system-site-packages", VENV_DIR }) + return pcall(ctx.spawn[executable], { "-m", "venv", VENV_DIR }) end, executables) Optional.of_nilable(executable) diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua index 30c25233c..cf7aff9bd 100644 --- a/tests/mason-core/managers/pip3_spec.lua +++ b/tests/mason-core/managers/pip3_spec.lua @@ -40,7 +40,6 @@ describe("pip3 manager", function() assert.spy(ctx.spawn.python3).was_called_with { "-m", "venv", - "--system-site-packages", "venv", } assert.spy(ctx.spawn.python).was_called(1)