From 42355e6222dc92fe1f7026059c819f5f1d657622 Mon Sep 17 00:00:00 2001 From: Rahul Iyer Date: Mon, 23 Jun 2025 16:40:55 -0700 Subject: [PATCH] feat(pypi): add setting to respect `g:python3_host_prog` if set --- lua/mason-core/installer/managers/pypi.lua | 4 ++++ lua/mason/health.lua | 3 +++ lua/mason/settings.lua | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/lua/mason-core/installer/managers/pypi.lua b/lua/mason-core/installer/managers/pypi.lua index 72b1b5037b..229fee815c 100644 --- a/lua/mason-core/installer/managers/pypi.lua +++ b/lua/mason-core/installer/managers/pypi.lua @@ -9,6 +9,7 @@ local pep440 = require "mason-core.pep440" local platform = require "mason-core.platform" local providers = require "mason-core.providers" local semver = require "mason-core.semver" +local settings = require "mason.settings" local spawn = require "mason-core.spawn" local M = {} @@ -85,6 +86,9 @@ local function create_venv(pkg) -- 1. Resolve stock python3 installation. local stock_candidates = platform.is.win and { "python", "python3" } or { "python3", "python" } + if settings.current.pip.use_python3_host_prog and vim.g.python3_host_prog then + table.insert(stock_candidates, 1, vim.g.python3_host_prog) + end local stock_target = resolve_python3(stock_candidates) if stock_target then log.fmt_debug("Resolved stock python3 installation version %s", stock_target.version) diff --git a/lua/mason/health.lua b/lua/mason/health.lua index b105940d04..03b99f6340 100644 --- a/lua/mason/health.lua +++ b/lua/mason/health.lua @@ -214,6 +214,9 @@ local function check_languages() check_thunk { cmd = "julia", args = { "--version" }, name = "julia", relaxed = true }, function() local python = platform.is.win and "python" or "python3" + if settings.current.pip.use_python3_host_prog and vim.g.python3_host_prog then + python = vim.g.python3_host_prog + end check { cmd = python, args = { "--version" }, name = "python", relaxed = true } check { cmd = python, args = { "-m", "pip", "--version" }, name = "pip", relaxed = true } check { diff --git a/lua/mason/settings.lua b/lua/mason/settings.lua index ebff1e0b44..5787cd9eb5 100644 --- a/lua/mason/settings.lua +++ b/lua/mason/settings.lua @@ -66,6 +66,10 @@ local DEFAULT_SETTINGS = { -- -- Example: { "--proxy", "https://proxyserver" } install_args = {}, + + ---@since 2.0.1 + -- Respect the `vim.g.python3_host_prog` while resolving packages from PyPI + use_python3_host_prog = false, }, ui = {