mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 11:38:31 +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>
This commit is contained in:
@@ -364,8 +364,14 @@ end
|
|||||||
|
|
||||||
-- Resolves Python executable path by invoking and checking `sys.executable`.
|
-- Resolves Python executable path by invoking and checking `sys.executable`.
|
||||||
local function python_exepath(invocation)
|
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()
|
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))
|
return vim.fs.normalize(vim.trim(p.stdout))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -790,35 +796,37 @@ local function python()
|
|||||||
--- @param v string
|
--- @param v string
|
||||||
venv_bins = vim.tbl_filter(function(v)
|
venv_bins = vim.tbl_filter(function(v)
|
||||||
-- XXX: Remove irrelevant executables found in bin/.
|
-- 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)
|
end, venv_bins)
|
||||||
if vim.tbl_count(venv_bins) > 0 then
|
if vim.tbl_count(venv_bins) > 0 then
|
||||||
for _, venv_bin in pairs(venv_bins) do
|
for _, venv_bin in pairs(venv_bins) do
|
||||||
venv_bin = vim.fs.normalize(venv_bin)
|
venv_bin = vim.fs.normalize(venv_bin)
|
||||||
local py_bin_basename = vim.fs.basename(venv_bin)
|
local py_bin_basename = vim.fs.basename(venv_bin)
|
||||||
local nvim_py_bin = python_exepath(vim.fn.exepath(py_bin_basename))
|
local nvim_py_bin = python_exepath(vim.fn.exepath(py_bin_basename))
|
||||||
local subshell_py_bin = python_exepath(py_bin_basename)
|
if nvim_py_bin then
|
||||||
if venv_bin ~= nvim_py_bin then
|
local subshell_py_bin = python_exepath(py_bin_basename)
|
||||||
errors[#errors + 1] = '$PATH yields this '
|
if venv_bin ~= nvim_py_bin then
|
||||||
.. py_bin_basename
|
errors[#errors + 1] = '$PATH yields this '
|
||||||
.. ' executable: '
|
.. py_bin_basename
|
||||||
.. nvim_py_bin
|
.. ' executable: '
|
||||||
local hint = '$PATH ambiguities arise if the virtualenv is not '
|
.. nvim_py_bin
|
||||||
.. 'properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, '
|
local hint = '$PATH ambiguities arise if the virtualenv is not '
|
||||||
.. 'check that invoking Python from the command line launches the correct one, '
|
.. 'properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, '
|
||||||
.. 'then relaunch Nvim.'
|
.. 'check that invoking Python from the command line launches the correct one, '
|
||||||
hints[hint] = true
|
.. 'then relaunch Nvim.'
|
||||||
end
|
hints[hint] = true
|
||||||
if venv_bin ~= subshell_py_bin then
|
end
|
||||||
errors[#errors + 1] = '$PATH in subshells yields this '
|
if venv_bin ~= subshell_py_bin then
|
||||||
.. py_bin_basename
|
errors[#errors + 1] = '$PATH in subshells yields this '
|
||||||
.. ' executable: '
|
.. py_bin_basename
|
||||||
.. subshell_py_bin
|
.. ' executable: '
|
||||||
local hint = '$PATH ambiguities in subshells typically are '
|
.. subshell_py_bin
|
||||||
.. 'caused by your shell config overriding the $PATH previously set by the '
|
local hint = '$PATH ambiguities in subshells typically are '
|
||||||
.. 'virtualenv. Either prevent them from doing so, or use this workaround: '
|
.. 'caused by your shell config overriding the $PATH previously set by the '
|
||||||
.. 'https://vi.stackexchange.com/a/34996'
|
.. 'virtualenv. Either prevent them from doing so, or use this workaround: '
|
||||||
hints[hint] = true
|
.. 'https://vi.stackexchange.com/a/34996'
|
||||||
|
hints[hint] = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -849,6 +857,7 @@ local function python()
|
|||||||
msgs[#msgs + 1] = msg
|
msgs[#msgs + 1] = msg
|
||||||
msgs[#msgs + 1] = conj
|
msgs[#msgs + 1] = conj
|
||||||
msgs[#msgs + 1] = err
|
msgs[#msgs + 1] = err
|
||||||
|
msgs[#msgs + 1] = '\n'
|
||||||
conj = '\nAnd '
|
conj = '\nAnd '
|
||||||
end
|
end
|
||||||
msgs[#msgs + 1] = '\nSo invoking Python may lead to unexpected results.'
|
msgs[#msgs + 1] = '\nSo invoking Python may lead to unexpected results.'
|
||||||
|
Reference in New Issue
Block a user