fix(health): hard fail on invalid "python-*" bin #35382

Problem:
Scripts named with 'python-…' prefix may not be valid python bins. If
such a script is found in a venv, the Python healthcheck fails hard.

    .venv/python-argcomplete-check-easy-install-script
    .venv/bin/python3.13
    .venv/bin/python

Solution:
- Discard known false-positives such as `python-argcomplete*`.
- Call `health.warn()` instead of `assert()` in `python_exepath()`.

Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
Judit Novak
2025-09-19 05:07:14 +02:00
committed by GitHub
parent e2166661d4
commit 6152bcf42e

View File

@@ -364,8 +364,14 @@ end
-- Resolves Python executable path by invoking and checking `sys.executable`.
local function python_exepath(invocation)
if invocation == '' or invocation == nil then
return nil
end
local p = vim.system({ invocation, '-c', 'import sys; sys.stdout.write(sys.executable)' }):wait()
assert(p.code == 0, p.stderr)
if p.code ~= 0 then
health.warn(p.stderr)
return nil
end
return vim.fs.normalize(vim.trim(p.stdout))
end
@@ -790,13 +796,14 @@ local function python()
--- @param v string
venv_bins = vim.tbl_filter(function(v)
-- XXX: Remove irrelevant executables found in bin/.
return not v:match('python.*%-config')
return not v:match('python.*%-config') and not v:match('python%-argcomplete')
end, venv_bins)
if vim.tbl_count(venv_bins) > 0 then
for _, venv_bin in pairs(venv_bins) do
venv_bin = vim.fs.normalize(venv_bin)
local py_bin_basename = vim.fs.basename(venv_bin)
local nvim_py_bin = python_exepath(vim.fn.exepath(py_bin_basename))
if nvim_py_bin then
local subshell_py_bin = python_exepath(py_bin_basename)
if venv_bin ~= nvim_py_bin then
errors[#errors + 1] = '$PATH yields this '
@@ -821,6 +828,7 @@ local function python()
hints[hint] = true
end
end
end
else
errors[#errors + 1] = 'no Python executables found in the virtualenv '
.. bin_dir
@@ -849,6 +857,7 @@ local function python()
msgs[#msgs + 1] = msg
msgs[#msgs + 1] = conj
msgs[#msgs + 1] = err
msgs[#msgs + 1] = '\n'
conj = '\nAnd '
end
msgs[#msgs + 1] = '\nSo invoking Python may lead to unexpected results.'