From 8f7f07fb58e7229ebbb3f3adbc269640b252e16e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 14 Apr 2015 19:26:56 +0200 Subject: [PATCH] Support for force_py_version = "auto" This will call `python` to look up its major version number. --- autoload/jedi.vim | 20 ++++++++++++++++++-- doc/jedi-vim.txt | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/autoload/jedi.vim b/autoload/jedi.vim index 39b4818..a2ceb08 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -309,7 +309,7 @@ let s:settings = { \ 'popup_select_first': 1, \ 'quickfix_window_height': 10, \ 'completions_enabled': 1, - \ 'force_py_version': 2 + \ 'force_py_version': "'auto'" \ } @@ -337,8 +337,24 @@ call s:init() let s:script_path = fnameescape(expand(':p:h:h')) +" Get g:jedi#force_py_version, handling "auto" on first call. +function! jedi#get_force_py_version() + if g:jedi#force_py_version == 'auto' + let s:def_py = system("python -c 'import sys; sys.stdout.write(str(sys.version_info[0]))'") + if v:shell_error == 0 && len(s:def_py) + let g:jedi#force_py_version = s:def_py + else + if !exists("g:jedi#squelch_py_warning") + echomsg "Error: jedi-vim failed to get Python version from sys.version_info: " . s:def_py + endif + endif + endif + return g:jedi#force_py_version +endfunction + if has('python') && has('python3') - call jedi#force_py_version(g:jedi#force_py_version) + " Use default python with Jedi. + call jedi#force_py_version(jedi#get_force_py_version()) elseif has('python') command! -nargs=1 Python python execute 'pyfile '.s:script_path.'/initialize.py' diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 81b1cda..d48f2ce 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -462,7 +462,7 @@ or set directly using this function, which has the same name as the variable: Function: `jedi#force_py_version(py_version)` Options: 2 or 3 -Default: 2 +Default: "auto" (will use sys.version_info from "python" in your $PATH) ============================================================================== 7. Testing *jedi-vim-testing*