Merge #9257 'health/python: warn if pynvim upgrade failed'

Reference: https://github.com/neovim/neovim/wiki/Following-HEAD#20181118
This commit is contained in:
Marco Hinz 2018-11-20 13:15:04 +01:00 committed by GitHub
commit 016ebb4185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 31 deletions

View File

@ -400,6 +400,8 @@ function! s:check_python(version) abort
endfor
endif
let pip = 'pip' . (a:version == 2 ? '' : '3')
if !empty(python_bin)
let [pyversion, current, latest, status] = s:version_info(python_bin)
if a:version != str2nr(pyversion)
@ -410,28 +412,35 @@ function! s:check_python(version) abort
call health#report_warn('Python 3.3+ is recommended.')
endif
call health#report_info('Python'.a:version.' version: ' . pyversion)
call health#report_info('Python version: ' . pyversion)
if s:is_bad_response(status)
call health#report_info(printf('%s-neovim version: %s (%s)', pyname, current, status))
call health#report_info(printf('pynvim version: %s (%s)', current, status))
else
call health#report_info(printf('%s-neovim version: %s', pyname, 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
if s:is_bad_response(current)
call health#report_error(
\ "Neovim Python client is not installed.\nError: ".current,
\ ['Run in shell: pip' . a:version . ' install pynvim'])
\ "pynvim is not installed.\nError: ".current,
\ ['Run in shell: '. pip .' install pynvim'])
endif
if s:is_bad_response(latest)
call health#report_warn('Could not contact PyPI to get latest version.')
call health#report_error('HTTP request failed: '.latest)
elseif s:is_bad_response(status)
call health#report_warn(printf('Latest %s-neovim is NOT installed: %s',
\ pyname, latest))
call health#report_warn(printf('Latest pynvim is NOT installed: %s', latest))
elseif !s:is_bad_response(current)
call health#report_ok(printf('Latest %s-neovim is installed: %s',
\ pyname, latest))
call health#report_ok(printf('Latest pynvim is installed.'))
endif
endif

View File

@ -40,7 +40,7 @@ function! provider#pythonx#Detect(major_ver) abort
let errors = []
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
return [prog, err]
endif
@ -54,46 +54,53 @@ function! provider#pythonx#Detect(major_ver) abort
\ . ":\n" . join(errors, "\n")]
endfunction
function! s:check_interpreter(prog, major_ver) abort
" Returns array: [prog_exitcode, prog_version]
function! s:import_module(prog, module) abort
let prog_version = system([a:prog, '-c' , printf(
\ 'import sys; ' .
\ 'sys.path.remove(""); ' .
\ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
\ 'import pkgutil; ' .
\ 'exit(2*int(pkgutil.get_loader("%s") is None))',
\ a:module)])
return [v:shell_error, prog_version]
endfunction
" Returns array: [was_success, error_message]
function! provider#pythonx#CheckForModule(prog, module, major_version) abort
let prog_path = exepath(a:prog)
if prog_path ==# ''
return [0, a:prog . ' not found in search path or not executable.']
endif
let min_version = (a:major_ver == 2) ? '2.6' : '3.3'
let min_version = (a:major_version == 2) ? '2.6' : '3.3'
" Try to load pynvim module, and output Python version.
" Return codes:
" Exit codes:
" 0 pynvim module can be loaded.
" 2 pynvim module cannot be loaded.
" Otherwise something else went wrong (e.g. 1 or 127).
let prog_ver = system([ a:prog , '-c' ,
\ 'import sys; ' .
\ 'sys.path.remove(""); ' .
\ 'sys.stdout.write(str(sys.version_info[0]) + "." + str(sys.version_info[1])); ' .
\ 'import pkgutil; ' .
\ 'exit(2*int(pkgutil.get_loader("pynvim") is None))'
\ ])
let [prog_exitcode, prog_version] = s:import_module(a:prog, 'pynvim')
if v:shell_error == 2 || v:shell_error == 0
if prog_exitcode == 2 || prog_exitcode == 0
" Check version only for expected return codes.
if prog_ver !~ '^' . a:major_ver
return [0, prog_path . ' is Python ' . prog_ver . ' and cannot provide Python '
\ . a:major_ver . '.']
elseif prog_ver =~ '^' . a:major_ver && prog_ver < min_version
return [0, prog_path . ' is Python ' . prog_ver . ' and cannot provide Python >= '
if prog_version !~ '^' . a:major_version
return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python '
\ . a:major_version . '.']
elseif prog_version =~ '^' . a:major_version && prog_version < min_version
return [0, prog_path . ' is Python ' . prog_version . ' and cannot provide Python >= '
\ . min_version . '.']
endif
endif
if v:shell_error == 2
if prog_exitcode == 2
return [0, prog_path.' does not have the "pynvim" module. :help provider-python']
elseif v:shell_error == 127
elseif prog_exitcode == 127
" This can happen with pyenv's shims.
return [0, prog_path . ' does not exist: ' . prog_ver]
elseif v:shell_error
return [0, prog_path . ' does not exist: ' . prog_version]
elseif prog_exitcode
return [0, 'Checking ' . prog_path . ' caused an unknown error. '
\ . '(' . v:shell_error . ', output: ' . prog_ver . ')'
\ . '(' . prog_exitcode . ', output: ' . prog_version . ')'
\ . ' Report this at https://github.com/neovim/neovim']
endif