mirror of
https://github.com/neovim/neovim.git
synced 2025-11-05 18:24:22 +00:00
health/python: warn if pynvim upgrade failed
Reference: https://github.com/neovim/neovim/wiki/Following-HEAD#20181118
This commit is contained in:
@@ -400,6 +400,8 @@ function! s:check_python(version) abort
|
|||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
let pip = 'pip' . (a:version == 2 ? '' : '3')
|
||||||
|
|
||||||
if !empty(python_bin)
|
if !empty(python_bin)
|
||||||
let [pyversion, current, latest, status] = s:version_info(python_bin)
|
let [pyversion, current, latest, status] = s:version_info(python_bin)
|
||||||
if a:version != str2nr(pyversion)
|
if a:version != str2nr(pyversion)
|
||||||
@@ -415,12 +417,21 @@ function! s:check_python(version) abort
|
|||||||
call health#report_info(printf('pynvim version: %s (%s)', current, status))
|
call health#report_info(printf('pynvim version: %s (%s)', current, status))
|
||||||
else
|
else
|
||||||
call health#report_info(printf('pynvim version: %s', current))
|
call health#report_info(printf('pynvim version: %s', current))
|
||||||
|
let [module_found, _msg] = provider#pythonx#CheckForModule(python_bin,
|
||||||
|
\ 'neovim', a:version)
|
||||||
|
if !module_found
|
||||||
|
call health#report_error('Importing "neovim" failed.',
|
||||||
|
\ "Reinstall \"pynvim\" and optionally \"neovim\" packages.\n" .
|
||||||
|
\ pip ." uninstall pynvim neovim\n" .
|
||||||
|
\ pip ." install pynvim\n" .
|
||||||
|
\ pip ." install neovim # only if needed by third-party software")
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:is_bad_response(current)
|
if s:is_bad_response(current)
|
||||||
call health#report_error(
|
call health#report_error(
|
||||||
\ "pynvim is not installed.\nError: ".current,
|
\ "pynvim is not installed.\nError: ".current,
|
||||||
\ ['Run in shell: pip' . a:version . ' install pynvim'])
|
\ ['Run in shell: '. pip .' install pynvim'])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if s:is_bad_response(latest)
|
if s:is_bad_response(latest)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function! provider#pythonx#Detect(major_ver) abort
|
|||||||
let errors = []
|
let errors = []
|
||||||
|
|
||||||
for prog in progs
|
for prog in progs
|
||||||
let [result, err] = s:check_interpreter(prog, a:major_ver)
|
let [result, err] = provider#pythonx#CheckForModule(prog, 'pynvim', a:major_ver)
|
||||||
if result
|
if result
|
||||||
return [prog, err]
|
return [prog, err]
|
||||||
endif
|
endif
|
||||||
@@ -54,19 +54,20 @@ function! provider#pythonx#Detect(major_ver) abort
|
|||||||
\ . ":\n" . join(errors, "\n")]
|
\ . ":\n" . join(errors, "\n")]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Returns array: [interpreter_exitcode, interpreter_version]
|
" Returns array: [prog_exitcode, prog_version]
|
||||||
function! s:check_for_package(prog, package) abort
|
function! s:import_module(prog, module) abort
|
||||||
let prog_version = system([a:prog, '-c' , printf(
|
let prog_version = system([a:prog, '-c' , printf(
|
||||||
\ 'import sys; ' .
|
\ 'import sys; ' .
|
||||||
\ 'sys.path.remove(""); ' .
|
\ 'sys.path.remove(""); ' .
|
||||||
\ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
|
\ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
|
||||||
\ 'import pkgutil; ' .
|
\ 'import pkgutil; ' .
|
||||||
\ 'exit(2*int(pkgutil.get_loader("%s") is None))',
|
\ 'exit(2*int(pkgutil.get_loader("%s") is None))',
|
||||||
\ a:package)])
|
\ a:module)])
|
||||||
return [v:shell_error, prog_version]
|
return [v:shell_error, prog_version]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:check_interpreter(prog, major_version) abort
|
" Returns array: [was_success, error_message]
|
||||||
|
function! provider#pythonx#CheckForModule(prog, module, major_version) abort
|
||||||
let prog_path = exepath(a:prog)
|
let prog_path = exepath(a:prog)
|
||||||
if prog_path ==# ''
|
if prog_path ==# ''
|
||||||
return [0, a:prog . ' not found in search path or not executable.']
|
return [0, a:prog . ' not found in search path or not executable.']
|
||||||
@@ -79,7 +80,7 @@ function! s:check_interpreter(prog, major_version) abort
|
|||||||
" 0 pynvim module can be loaded.
|
" 0 pynvim module can be loaded.
|
||||||
" 2 pynvim module cannot be loaded.
|
" 2 pynvim module cannot be loaded.
|
||||||
" Otherwise something else went wrong (e.g. 1 or 127).
|
" Otherwise something else went wrong (e.g. 1 or 127).
|
||||||
let [prog_exitcode, prog_version] = s:check_for_package(a:prog, 'pynvim')
|
let [prog_exitcode, prog_version] = s:import_module(a:prog, 'pynvim')
|
||||||
|
|
||||||
if prog_exitcode == 2 || prog_exitcode == 0
|
if prog_exitcode == 2 || prog_exitcode == 0
|
||||||
" Check version only for expected return codes.
|
" Check version only for expected return codes.
|
||||||
|
|||||||
Reference in New Issue
Block a user