Create the importer stuff Python2.7 and 3.3

This commit is contained in:
Dave Halter
2018-01-21 15:46:40 +01:00
parent baacb5ec0d
commit 7fcbf7b5f0
+24 -13
View File
@@ -1,10 +1,20 @@
import sys import sys
import os import os
def _get_paths():
# Get the path to jedi.
_d = os.path.dirname
_jedi_path = _d(_d(_d(_d(_d(__file__)))))
_parso_path = sys.argv[1]
# The paths are the directory that jedi and parso lie in.
return {'jedi': _jedi_path, 'parso': _parso_path}
if sys.version_info > (3, 4):
from importlib.machinery import FileFinder from importlib.machinery import FileFinder
class _ExactImporter(object):
class ExactImporter(object):
def __init__(self, path_dct): def __init__(self, path_dct):
self._path_dct = path_dct self._path_dct = path_dct
@@ -14,24 +24,25 @@ class ExactImporter(object):
return loader return loader
return None return None
def _create_importer():
# Get the path to jedi.
_d = os.path.dirname
_jedi_path = _d(_d(_d(_d(_d(__file__)))))
_parso_path = sys.argv[1]
# The paths are the directory that jedi and parso lie in.
return ExactImporter({'jedi': _jedi_path, 'parso': _parso_path})
# Remove the first entry, because it's simply a directory entry that equals # Remove the first entry, because it's simply a directory entry that equals
# this directory. # this directory.
del sys.path[0] del sys.path[0]
# Try to import jedi/parso. # Try to import jedi/parso.
sys.meta_path.insert(0, _create_importer()) sys.meta_path.insert(0, _ExactImporter(_get_paths()))
from jedi.evaluate.compiled import subprocess # NOQA from jedi.evaluate.compiled import subprocess # NOQA
sys.meta_path.pop(0) sys.meta_path.pop(0)
else:
import imp
def load(name):
paths = list(_get_paths().values())
fp, pathname, description = imp.find_module(name, paths)
return imp.load_module(name, fp, pathname, description)
load('parso')
load('jedi')
from jedi.evaluate.compiled import subprocess # NOQA
# And finally start the client. # And finally start the client.
subprocess.Listener().listen() subprocess.Listener().listen()