2015-03-20 15:55:39 -07:00
|
|
|
" The Python provider helper
|
|
|
|
if exists('s:loaded_pythonx_provider')
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
|
|
|
|
let s:loaded_pythonx_provider = 1
|
|
|
|
|
|
|
|
function! provider#pythonx#Detect(ver) abort
|
|
|
|
let host_var = (a:ver == 2) ?
|
|
|
|
\ 'g:python_host_prog' : 'g:python3_host_prog'
|
|
|
|
let skip_var = (a:ver == 2) ?
|
|
|
|
\ 'g:python_host_skip_check' : 'g:python3_host_skip_check'
|
|
|
|
let skip = exists(skip_var) ? {skip_var} : 0
|
|
|
|
if exists(host_var)
|
|
|
|
" Disable auto detection
|
2015-04-30 19:28:54 -07:00
|
|
|
let [check, err, _] = s:check_interpreter({host_var}, a:ver, skip)
|
2015-03-20 15:55:39 -07:00
|
|
|
return check ? [{host_var}, err] : ['', err]
|
|
|
|
endif
|
|
|
|
|
|
|
|
let detect_versions = (a:ver == 2) ?
|
|
|
|
\ ['2.7', '2.6', '2', '']
|
|
|
|
\ : ['3.5', '3.4', '3.3', '3.2', '3', '']
|
|
|
|
|
|
|
|
for prog in map(detect_versions, "'python' . v:val")
|
2015-04-30 19:28:54 -07:00
|
|
|
let [check, err, ver] = s:check_interpreter(prog, a:ver, skip)
|
2015-03-20 15:55:39 -07:00
|
|
|
if check
|
2015-04-30 19:28:54 -07:00
|
|
|
let [check, err] = s:check_version(prog, ver, skip)
|
2015-03-20 15:55:39 -07:00
|
|
|
return [prog, err]
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
" No Python interpreter
|
|
|
|
return ['', 'Neovim module installed Python'
|
|
|
|
\ .a:ver.' interpreter is not found.']
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:check_version(prog, ver, skip) abort
|
|
|
|
if a:skip
|
|
|
|
return [1, '']
|
|
|
|
endif
|
|
|
|
|
2015-04-30 19:28:54 -07:00
|
|
|
let min_version = (a:ver[0] == 2) ? '2.6' : '3.3'
|
|
|
|
if a:ver >= min_version
|
2015-03-20 15:55:39 -07:00
|
|
|
return [1, '']
|
|
|
|
endif
|
2015-04-30 19:28:54 -07:00
|
|
|
return [0, 'Python ' . a:ver . ' interpreter is not supported.']
|
2015-03-20 15:55:39 -07:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:check_interpreter(prog, ver, skip) abort
|
|
|
|
if !executable(a:prog)
|
2015-04-30 19:28:54 -07:00
|
|
|
return [0, 'Python'.a:ver.' interpreter is not executable.', '']
|
2015-03-20 15:55:39 -07:00
|
|
|
endif
|
|
|
|
|
|
|
|
if a:skip
|
2015-04-30 19:28:54 -07:00
|
|
|
return [1, '', '']
|
2015-03-20 15:55:39 -07:00
|
|
|
endif
|
|
|
|
|
2015-05-02 11:56:09 -07:00
|
|
|
" Try to load neovim module, and output Python version.
|
2015-04-30 19:28:54 -07:00
|
|
|
let ver = system(a:prog . ' -c ' .
|
|
|
|
\ '''import sys; sys.stdout.write(str(sys.version_info[0]) + '.
|
|
|
|
\ '"." + str(sys.version_info[1])); '''.
|
2015-03-20 15:55:39 -07:00
|
|
|
\ (a:ver == 2 ?
|
|
|
|
\ '''import pkgutil; exit(pkgutil.get_loader("neovim") is None)''':
|
|
|
|
\ '''import importlib; exit(importlib.find_loader("neovim") is None)''')
|
|
|
|
\ )
|
2015-05-02 11:56:09 -07:00
|
|
|
if v:shell_error
|
2015-05-02 12:00:33 -07:00
|
|
|
return [0, 'Python'.a:ver.' interpreter ('.a:prog.') has no neovim module installed. See ":help nvim-python".', ver]
|
2015-05-02 11:56:09 -07:00
|
|
|
endif
|
|
|
|
return [1, '', ver]
|
2015-03-20 15:55:39 -07:00
|
|
|
endfunction
|
|
|
|
|