mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 03:58:32 +00:00
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>
(cherry picked from commit 6152bcf42e
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
77fe01f200
commit
8e00534b1e
@@ -359,8 +359,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
|
||||
|
||||
@@ -782,35 +788,37 @@ 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))
|
||||
local subshell_py_bin = python_exepath(py_bin_basename)
|
||||
if venv_bin ~= nvim_py_bin then
|
||||
errors[#errors + 1] = '$PATH yields this '
|
||||
.. py_bin_basename
|
||||
.. ' executable: '
|
||||
.. nvim_py_bin
|
||||
local hint = '$PATH ambiguities arise if the virtualenv is not '
|
||||
.. 'properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, '
|
||||
.. 'check that invoking Python from the command line launches the correct one, '
|
||||
.. 'then relaunch Nvim.'
|
||||
hints[hint] = true
|
||||
end
|
||||
if venv_bin ~= subshell_py_bin then
|
||||
errors[#errors + 1] = '$PATH in subshells yields this '
|
||||
.. py_bin_basename
|
||||
.. ' executable: '
|
||||
.. subshell_py_bin
|
||||
local hint = '$PATH ambiguities in subshells typically are '
|
||||
.. 'caused by your shell config overriding the $PATH previously set by the '
|
||||
.. 'virtualenv. Either prevent them from doing so, or use this workaround: '
|
||||
.. 'https://vi.stackexchange.com/a/34996'
|
||||
hints[hint] = true
|
||||
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 '
|
||||
.. py_bin_basename
|
||||
.. ' executable: '
|
||||
.. nvim_py_bin
|
||||
local hint = '$PATH ambiguities arise if the virtualenv is not '
|
||||
.. 'properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, '
|
||||
.. 'check that invoking Python from the command line launches the correct one, '
|
||||
.. 'then relaunch Nvim.'
|
||||
hints[hint] = true
|
||||
end
|
||||
if venv_bin ~= subshell_py_bin then
|
||||
errors[#errors + 1] = '$PATH in subshells yields this '
|
||||
.. py_bin_basename
|
||||
.. ' executable: '
|
||||
.. subshell_py_bin
|
||||
local hint = '$PATH ambiguities in subshells typically are '
|
||||
.. 'caused by your shell config overriding the $PATH previously set by the '
|
||||
.. 'virtualenv. Either prevent them from doing so, or use this workaround: '
|
||||
.. 'https://vi.stackexchange.com/a/34996'
|
||||
hints[hint] = true
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
@@ -841,6 +849,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.'
|
||||
|
Reference in New Issue
Block a user