Merge #5519 from blueyed/improve-python-health-check

Improve Python health check
This commit is contained in:
Justin M. Keyes 2017-01-09 00:07:13 +01:00 committed by GitHub
commit 1420e10474

View File

@ -37,6 +37,7 @@ endfunction
function! s:system(cmd, ...) abort function! s:system(cmd, ...) abort
let stdin = a:0 ? a:1 : '' let stdin = a:0 ? a:1 : ''
let ignore_stderr = a:0 > 1 ? a:2 : 0 let ignore_stderr = a:0 > 1 ? a:2 : 0
let ignore_error = a:0 > 2 ? a:3 : 0
let opts = { let opts = {
\ 'output': '', \ 'output': '',
\ 'on_stdout': function('s:system_handler'), \ 'on_stdout': function('s:system_handler'),
@ -63,7 +64,7 @@ function! s:system(cmd, ...) abort
call health#report_error(printf('Command timed out: %s', call health#report_error(printf('Command timed out: %s',
\ type(a:cmd) == type([]) ? join(a:cmd) : a:cmd)) \ type(a:cmd) == type([]) ? join(a:cmd) : a:cmd))
call jobstop(jobid) call jobstop(jobid)
elseif s:shell_error != 0 elseif s:shell_error != 0 && !ignore_error
call health#report_error(printf("Command error (%d) %s: %s", jobid, call health#report_error(printf("Command error (%d) %s: %s", jobid,
\ type(a:cmd) == type([]) ? join(a:cmd) : a:cmd, \ type(a:cmd) == type([]) ? join(a:cmd) : a:cmd,
\ opts.output)) \ opts.output))
@ -83,8 +84,8 @@ endfunction
" Fetch the contents of a URL. " Fetch the contents of a URL.
function! s:download(url) abort function! s:download(url) abort
if executable('curl') if executable('curl')
let rv = s:system(['curl', '-sL', a:url]) let rv = s:system(['curl', '-sL', a:url], '', 1, 1)
return s:shell_error ? 'curl error: '.s:shell_error : rv return s:shell_error ? 'curl error with '.a:url.': '.s:shell_error : rv
elseif executable('python') elseif executable('python')
let script = " let script = "
\try:\n \try:\n
@ -155,13 +156,10 @@ function! s:version_info(python) abort
endif endif
let nvim_path = s:trim(s:system([ let nvim_path = s:trim(s:system([
\ a:python, \ a:python, '-c', 'import neovim; print(neovim.__file__)']))
\ '-c', if s:shell_error || empty(nvim_path)
\ 'import neovim; print(neovim.__file__)'])) return [python_version, 'unable to load neovim Python module', pypi_version,
let nvim_path = s:shell_error ? '' : nvim_path \ nvim_path]
if empty(nvim_path)
return [python_version, 'unable to find nvim executable', pypi_version, 'unable to get nvim executable']
endif endif
" Assuming that multiple versions of a package are installed, sort them " Assuming that multiple versions of a package are installed, sort them
@ -172,24 +170,34 @@ function! s:version_info(python) abort
return a == b ? 0 : a > b ? 1 : -1 return a == b ? 0 : a > b ? 1 : -1
endfunction endfunction
let nvim_version = 'unable to find nvim version' " Try to get neovim.VERSION (added in 0.1.11dev).
let base = fnamemodify(nvim_path, ':h') let nvim_version = s:system(['python', '-c',
let metas = glob(base.'-*/METADATA', 1, 1) + glob(base.'-*/PKG-INFO', 1, 1) \ 'from neovim import VERSION as v; '.
let metas = sort(metas, 's:compare') \ 'print("{}.{}.{}{}".format(v.major, v.minor, v.patch, v.prerelease))'],
\ '', 1, 1)
if empty(nvim_version)
let nvim_version = 'unable to find neovim Python module version'
let base = fnamemodify(nvim_path, ':h')
let metas = glob(base.'-*/METADATA', 1, 1)
\ + glob(base.'-*/PKG-INFO', 1, 1)
\ + glob(base.'.egg-info/PKG-INFO', 1, 1)
let metas = sort(metas, 's:compare')
if !empty(metas) if !empty(metas)
for meta_line in readfile(metas[0]) for meta_line in readfile(metas[0])
if meta_line =~# '^Version:' if meta_line =~# '^Version:'
let nvim_version = matchstr(meta_line, '^Version: \zs\S\+') let nvim_version = matchstr(meta_line, '^Version: \zs\S\+')
break break
endif endif
endfor endfor
endif
endif endif
let version_status = 'unknown' let nvim_path_base = fnamemodify(nvim_path, ':~:h')
let version_status = 'unknown; '.nvim_path_base
if !s:is_bad_response(nvim_version) && !s:is_bad_response(pypi_version) if !s:is_bad_response(nvim_version) && !s:is_bad_response(pypi_version)
if s:version_cmp(nvim_version, pypi_version) == -1 if s:version_cmp(nvim_version, pypi_version) == -1
let version_status = 'outdated' let version_status = 'outdated; from '.nvim_path_base
else else
let version_status = 'up to date' let version_status = 'up to date'
endif endif
@ -372,7 +380,11 @@ function! s:check_python(version) abort
endif endif
call health#report_info('Python'.a:version.' version: ' . pyversion) call health#report_info('Python'.a:version.' version: ' . pyversion)
call health#report_info(printf('%s-neovim version: %s', python_bin_name, current)) if s:is_bad_response(status)
call health#report_info(printf('%s-neovim version: %s (%s)', python_bin_name, current, status))
else
call health#report_info(printf('%s-neovim version: %s', python_bin_name, current))
endif
if s:is_bad_response(current) if s:is_bad_response(current)
call health#report_error( call health#report_error(
@ -381,14 +393,12 @@ function! s:check_python(version) abort
endif endif
if s:is_bad_response(latest) if s:is_bad_response(latest)
call health#report_warn('Unable to contact PyPI.') call health#report_warn('Could not contact PyPI to get latest version.')
call health#report_error('HTTP request failed: '.latest) call health#report_error('HTTP request failed: '.latest)
endif elseif s:is_bad_response(status)
if s:is_bad_response(status)
call health#report_warn(printf('Latest %s-neovim is NOT installed: %s', call health#report_warn(printf('Latest %s-neovim is NOT installed: %s',
\ python_bin_name, latest)) \ python_bin_name, latest))
elseif !s:is_bad_response(latest) elseif !s:is_bad_response(current)
call health#report_ok(printf('Latest %s-neovim is installed: %s', call health#report_ok(printf('Latest %s-neovim is installed: %s',
\ python_bin_name, latest)) \ python_bin_name, latest))
endif endif