mirror of
https://github.com/davidhalter/jedi.git
synced 2026-03-05 02:14:15 +08:00
Remove a way for using imp to load Jedi in a subprocess
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from importlib.machinery import PathFinder
|
||||||
|
|
||||||
|
# Remove the first entry, because it's simply a directory entry that equals
|
||||||
|
# this directory.
|
||||||
|
del sys.path[0]
|
||||||
|
|
||||||
|
|
||||||
def _get_paths():
|
def _get_paths():
|
||||||
@@ -11,39 +16,22 @@ def _get_paths():
|
|||||||
return {'jedi': _jedi_path, 'parso': _parso_path}
|
return {'jedi': _jedi_path, 'parso': _parso_path}
|
||||||
|
|
||||||
|
|
||||||
# Remove the first entry, because it's simply a directory entry that equals
|
class _ExactImporter(object):
|
||||||
# this directory.
|
def __init__(self, path_dct):
|
||||||
del sys.path[0]
|
self._path_dct = path_dct
|
||||||
|
|
||||||
if sys.version_info > (3, 4):
|
def find_module(self, fullname, path=None):
|
||||||
from importlib.machinery import PathFinder
|
if path is None and fullname in self._path_dct:
|
||||||
|
p = self._path_dct[fullname]
|
||||||
|
loader = PathFinder.find_module(fullname, path=[p])
|
||||||
|
return loader
|
||||||
|
return None
|
||||||
|
|
||||||
class _ExactImporter(object):
|
|
||||||
def __init__(self, path_dct):
|
|
||||||
self._path_dct = path_dct
|
|
||||||
|
|
||||||
def find_module(self, fullname, path=None):
|
# Try to import jedi/parso.
|
||||||
if path is None and fullname in self._path_dct:
|
sys.meta_path.insert(0, _ExactImporter(_get_paths()))
|
||||||
p = self._path_dct[fullname]
|
from jedi.inference.compiled import subprocess # NOQA
|
||||||
loader = PathFinder.find_module(fullname, path=[p])
|
sys.meta_path.pop(0)
|
||||||
return loader
|
|
||||||
return None
|
|
||||||
|
|
||||||
# Try to import jedi/parso.
|
|
||||||
sys.meta_path.insert(0, _ExactImporter(_get_paths()))
|
|
||||||
from jedi.inference.compiled import subprocess # NOQA
|
|
||||||
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.inference.compiled import subprocess # NOQA
|
|
||||||
|
|
||||||
from jedi._compatibility import highest_pickle_protocol # noqa: E402
|
from jedi._compatibility import highest_pickle_protocol # noqa: E402
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user