Use Vim's pythonx mechanism

Move jedi_vim.py and the jedi submodule into pythonx, which gets added
to Vim's internal sys.path.  While jedi cannot be imported directly from
there, it still makes sense for consistency.
This commit is contained in:
Daniel Hahler
2017-08-08 04:40:45 +02:00
committed by Dave Halter
parent cfadac7f22
commit 163a0b5db1
4 changed files with 20 additions and 24 deletions

View File

@@ -152,29 +152,20 @@ function! jedi#setup_py_version(py_version) abort
execute 'command! -nargs=1 PythonJedi '.cmd_exec.' <args>'
let s:init_outcome = 0
PythonJedi << EOF
try:
import vim
import os, sys
jedi_path = os.path.join(vim.eval('expand(s:script_path)'), 'jedi')
sys.path.insert(0, jedi_path)
jedi_vim_path = vim.eval('expand(s:script_path)')
if jedi_vim_path not in sys.path: # Might happen when reloading.
sys.path.insert(0, jedi_vim_path)
except Exception as excinfo:
vim.command('let s:init_outcome = "error when adding to sys.path: {0}: {1}"'.format(excinfo.__class__.__name__, excinfo))
else:
try:
import jedi_vim
except Exception as excinfo:
vim.command('let s:init_outcome = "error when importing jedi_vim: {0}: {1}"'.format(excinfo.__class__.__name__, excinfo))
else:
vim.command('let s:init_outcome = 1')
finally:
sys.path.remove(jedi_path)
EOF
let init_lines = [
\ 'import vim',
\ 'vim.command(''let s:init_outcome = 0'')',
\ 'try:',
\ ' import jedi_vim',
\ 'except Exception as exc:',
\ ' vim.command(''let s:init_outcome = "could not import jedi_vim: {0}: {1}"''.format(exc.__class__.__name__, exc))',
\ 'else:',
\ ' vim.command(''let s:init_outcome = 1'')']
try
exe 'PythonJedi exec('''.escape(join(init_lines, '\n'), "'").''')'
catch
throw printf('jedi#setup_py_version: failed to run Python for initialization: %s.', v:exception)
endtry
if !exists('s:init_outcome')
throw 'jedi#setup_py_version: failed to run Python for initialization.'
elseif s:init_outcome isnot 1