aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJongwook Choi <wookayin@gmail.com>2023-09-23 05:49:34 -0400
committerGitHub <noreply@github.com>2023-09-23 02:49:34 -0700
commit7bd6bd1ef7214942e94c9238e08619adf41f5995 (patch)
treeb5c33b77f67a79d50be8c7bba87226afab0d3925
parentb8103eece30dab8add09e134820b690d9fd00330 (diff)
downloadrneovim-7bd6bd1ef7214942e94c9238e08619adf41f5995.tar.gz
rneovim-7bd6bd1ef7214942e94c9238e08619adf41f5995.tar.bz2
rneovim-7bd6bd1ef7214942e94c9238e08619adf41f5995.zip
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
-rw-r--r--runtime/autoload/provider/pythonx.vim9
1 files changed, 4 insertions, 5 deletions
diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim
index 6211b457d6..db6acf4526 100644
--- a/runtime/autoload/provider/pythonx.vim
+++ b/runtime/autoload/provider/pythonx.vim
@@ -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