mirror of
https://github.com/neovim/neovim.git
synced 2024-09-17 20:58:20 -04:00
fix(provider): cannot detect python3.12 #25316
PROBLEM: The builtin python3 provider cannot auto-detect python3.12 when g:python3_host_prog is not set. As a result, when python3 on $PATH is currently python 3.12, neovim will fail to load python3 provider and result in `has("python3") == 0`, e.g., "Failed to load python3 host. You can try to see what happened by ..." ROOT CAUSE: the `system()` call from `provider#pythonx#DetectByModule` does not ignore python warnings, and `pkgutil.get_loader` will print a warning message in the very first line: ``` <string>:1: DeprecationWarning: 'pkgutil.get_loader' is deprecated and slated for removal in Python 3.14; use importlib.util.find_spec() instead ``` SOLUTION: - Use `importlib.util.find_spec` instead (python >= 3.4) - Use `-W ignore` option to prevent any potential warning messages
This commit is contained in:
parent
b8103eece3
commit
7bd6bd1ef7
@ -26,7 +26,7 @@ endfunction
|
||||
|
||||
function! s:get_python_candidates(major_version) abort
|
||||
return {
|
||||
\ 3: ['python3', 'python3.10', 'python3.9', 'python3.8', 'python3.7', 'python']
|
||||
\ 3: ['python3', 'python3.12', 'python3.11', 'python3.10', 'python3.9', 'python3.8', 'python3.7', 'python']
|
||||
\ }[a:major_version]
|
||||
endfunction
|
||||
|
||||
@ -61,12 +61,11 @@ endfunction
|
||||
|
||||
" Returns array: [prog_exitcode, prog_version]
|
||||
function! s:import_module(prog, module) abort
|
||||
let prog_version = system([a:prog, '-c' , printf(
|
||||
\ 'import sys; ' .
|
||||
let prog_version = system([a:prog, '-W', 'ignore', '-c', printf(
|
||||
\ 'import sys, importlib; ' .
|
||||
\ 'sys.path = [p for p in sys.path if p != ""]; ' .
|
||||
\ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
|
||||
\ 'import pkgutil; ' .
|
||||
\ 'exit(2*int(pkgutil.get_loader("%s") is None))',
|
||||
\ 'sys.exit(2 * int(importlib.util.find_spec("%s") is None))',
|
||||
\ a:module)])
|
||||
return [v:shell_error, prog_version]
|
||||
endfunction
|
||||
|
Loading…
Reference in New Issue
Block a user