diff options
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | doc/mason.txt | 3 | ||||
| -rw-r--r-- | lua/mason-core/managers/pip3/init.lua | 12 | ||||
| -rw-r--r-- | lua/mason/settings.lua | 5 | ||||
| -rw-r--r-- | tests/mason-core/managers/pip3_spec.lua | 41 |
5 files changed, 63 insertions, 1 deletions
@@ -163,6 +163,9 @@ local DEFAULT_SETTINGS = { PATH = "prepend", pip = { + -- Whether to upgrade pip to the latest version in the virtual environment before installing packages. + upgrade_pip = false, + -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior -- and is not recommended. -- diff --git a/doc/mason.txt b/doc/mason.txt index d16dbc40..645a15c1 100644 --- a/doc/mason.txt +++ b/doc/mason.txt @@ -215,6 +215,9 @@ Example: PATH = "prepend", pip = { + -- Whether to upgrade pip to the latest version in the virtual environment before installing packages. + upgrade_pip = false, + -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior -- and is not recommended. -- diff --git a/lua/mason-core/managers/pip3/init.lua b/lua/mason-core/managers/pip3/init.lua index 67f70a89..aeca0ce0 100644 --- a/lua/mason-core/managers/pip3/init.lua +++ b/lua/mason-core/managers/pip3/init.lua @@ -64,6 +64,18 @@ function M.install(packages) Optional.of_nilable(executable) :if_present(function() + if settings.current.pip.upgrade_pip then + ctx.spawn.python { + "-m", + "pip", + "--disable-pip-version-check", + "install", + "-U", + settings.current.pip.install_args, + "pip", + with_paths = { M.venv_path(ctx.cwd:get()) }, + } + end ctx.spawn.python { "-m", "pip", diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua index 4322988f..9bdc0f9c 100644 --- a/lua/mason/settings.lua +++ b/lua/mason/settings.lua @@ -15,6 +15,9 @@ local DEFAULT_SETTINGS = { PATH = "prepend", pip = { + -- Whether to upgrade pip to the latest version in the virtual environment before installing packages. + upgrade_pip = false, + -- These args will be added to `pip install` calls. Note that setting extra args might impact intended behavior -- and is not recommended. -- @@ -92,7 +95,7 @@ M.current = M._DEFAULT_SETTINGS ---@param opts MasonSettings function M.set(opts) - M.current = vim.tbl_deep_extend("force", M.current, opts) + M.current = vim.tbl_deep_extend("force", vim.deepcopy(M.current), opts) end return M diff --git a/tests/mason-core/managers/pip3_spec.lua b/tests/mason-core/managers/pip3_spec.lua index ffba9b04..601ee839 100644 --- a/tests/mason-core/managers/pip3_spec.lua +++ b/tests/mason-core/managers/pip3_spec.lua @@ -13,6 +13,10 @@ local spawn = require "mason-core.spawn" local api = require "mason-registry.api" describe("pip3 manager", function() + before_each(function() + settings.set(settings._DEFAULT_SETTINGS) + end) + it("normalizes pip3 packages", function() local normalize = pip3.normalize_package assert.equals("python-lsp-server", normalize "python-lsp-server[all]") @@ -117,6 +121,7 @@ describe("pip3 manager", function() local handle = InstallHandleGenerator "dummy" local ctx = InstallContextGenerator(handle) installer.run_installer(ctx, pip3.packages { "package" }) + assert.spy(ctx.spawn.python).was_called(1) assert.spy(ctx.spawn.python).was_called_with { "-m", "pip", @@ -131,6 +136,42 @@ describe("pip3 manager", function() ) it( + "should upgrade pip", + async_test(function() + settings.set { + pip = { + upgrade_pip = true, + }, + } + local handle = InstallHandleGenerator "dummy" + local ctx = InstallContextGenerator(handle) + installer.run_installer(ctx, pip3.packages { "package" }) + vim.pretty_print(ctx.spawn.python) + assert.spy(ctx.spawn.python).was_called(2) + assert.spy(ctx.spawn.python).was_called_with { + "-m", + "pip", + "--disable-pip-version-check", + "install", + "-U", + {}, + "pip", + with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, + } + assert.spy(ctx.spawn.python).was_called_with { + "-m", + "pip", + "--disable-pip-version-check", + "install", + "-U", + {}, + { "package" }, + with_paths = { path.concat { path.package_prefix "dummy", "venv", "bin" } }, + } + end) + ) + + it( "should provide receipt information", async_test(function() local handle = InstallHandleGenerator "dummy" |
