Use the PathFinder, because the FileFinder doesn't work without suffixes

This feels more like importlib was intended to be used anyway.
This commit is contained in:
Dave Halter
2018-01-21 23:52:44 +01:00
parent 7fcbf7b5f0
commit 4653c30fa4

View File

@@ -11,8 +11,12 @@ def _get_paths():
return {'jedi': _jedi_path, 'parso': _parso_path}
# Remove the first entry, because it's simply a directory entry that equals
# this directory.
del sys.path[0]
if sys.version_info > (3, 4):
from importlib.machinery import FileFinder
from importlib.machinery import PathFinder
class _ExactImporter(object):
def __init__(self, path_dct):
@@ -20,14 +24,11 @@ if sys.version_info > (3, 4):
def find_module(self, fullname, path=None):
if path is None and fullname in self._path_dct:
loader, _ = FileFinder(self._path_dct[fullname]).find_loader(fullname)
p = self._path_dct[fullname]
loader = PathFinder.find_module(fullname, path=[p])
return loader
return None
# Remove the first entry, because it's simply a directory entry that equals
# this directory.
del sys.path[0]
# Try to import jedi/parso.
sys.meta_path.insert(0, _ExactImporter(_get_paths()))
from jedi.evaluate.compiled import subprocess # NOQA