aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/provider/pythonx.vim
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2019-01-11 02:03:56 +0100
committerGitHub <noreply@github.com>2019-01-11 02:03:56 +0100
commit8986f70bdc07b2d92bbcf4ef3f63db48934cfbe1 (patch)
tree817edb7afbeabe5ec745cb8e0d6f7d185255aec4 /runtime/autoload/provider/pythonx.vim
parent99429e5f415bfbb8298142c0e10b76a7ef9428bf (diff)
parent75593e6fcebcfd1404c8851653d5d8b1195ee34c (diff)
downloadrneovim-8986f70bdc07b2d92bbcf4ef3f63db48934cfbe1.tar.gz
rneovim-8986f70bdc07b2d92bbcf4ef3f63db48934cfbe1.tar.bz2
rneovim-8986f70bdc07b2d92bbcf4ef3f63db48934cfbe1.zip
Merge #9468 'checkhealth: detect broken pip"'
Diffstat (limited to 'runtime/autoload/provider/pythonx.vim')
-rw-r--r--runtime/autoload/provider/pythonx.vim54
1 files changed, 31 insertions, 23 deletions
diff --git a/runtime/autoload/provider/pythonx.vim b/runtime/autoload/provider/pythonx.vim
index 05b04e7e2c..59b1c27b72 100644
--- a/runtime/autoload/provider/pythonx.vim
+++ b/runtime/autoload/provider/pythonx.vim
@@ -21,37 +21,45 @@ function! provider#pythonx#Require(host) abort
return provider#Poll(args, a:host.orig_name, '$NVIM_PYTHON_LOG_FILE')
endfunction
-function! provider#pythonx#Detect(major_ver) abort
- if a:major_ver == 2
- if exists('g:python_host_prog')
- return [expand(g:python_host_prog), '']
- else
- let progs = ['python2', 'python2.7', 'python2.6', 'python']
- endif
- else
- if exists('g:python3_host_prog')
- return [expand(g:python3_host_prog), '']
- else
- let progs = ['python3', 'python3.7', 'python3.6', 'python3.5',
- \ 'python3.4', 'python3.3', 'python']
- endif
+function! s:get_python_executable_from_host_var(major_version) abort
+ return expand(get(g:, 'python'.(a:major_version == 3 ? '3' : '').'_host_prog', ''))
+endfunction
+
+function! s:get_python_candidates(major_version) abort
+ return {
+ \ 2: ['python2', 'python2.7', 'python2.6', 'python'],
+ \ 3: ['python3', 'python3.7', 'python3.6', 'python3.5', 'python3.4', 'python3.3',
+ \ 'python']
+ \ }[a:major_version]
+endfunction
+
+" Returns [path_to_python_executable, error_message]
+function! provider#pythonx#Detect(major_version) abort
+ return provider#pythonx#DetectByModule('neovim', a:major_version)
+endfunction
+
+" Returns [path_to_python_executable, error_message]
+function! provider#pythonx#DetectByModule(module, major_version) abort
+ let python_exe = s:get_python_executable_from_host_var(a:major_version)
+
+ if !empty(python_exe)
+ return [python_exe, '']
endif
+ let candidates = s:get_python_candidates(a:major_version)
let errors = []
- for prog in progs
- let [result, err] = provider#pythonx#CheckForModule(prog, 'neovim', a:major_ver)
+ for exe in candidates
+ let [result, error] = provider#pythonx#CheckForModule(exe, a:module, a:major_version)
if result
- return [prog, err]
+ return [exe, error]
endif
- " Accumulate errors in case we don't find
- " any suitable Python interpreter.
- call add(errors, err)
+ " Accumulate errors in case we don't find any suitable Python executable.
+ call add(errors, error)
endfor
- " No suitable Python interpreter found.
- return ['', 'provider/pythonx: Could not load Python ' . a:major_ver
- \ . ":\n" . join(errors, "\n")]
+ " No suitable Python executable found.
+ return ['', 'provider/pythonx: Could not load Python '.a:major_version.":\n".join(errors, "\n")]
endfunction
" Returns array: [prog_exitcode, prog_version]