Format: text/x-python
⬇ Download File (1.2 KB)
   1  import os
   2  import sys
   3  from importlib.abc import MetaPathFinder
   4  from importlib.machinery import PathFinder
   5  
   6  # Remove the first entry, because it's simply a directory entry that equals
   7  # this directory.
   8  del sys.path[0]
   9  
  10  
  11  def _get_paths():
  12      # Get the path to jedi.
  13      _d = os.path.dirname
  14      _jedi_path = _d(_d(_d(_d(_d(__file__)))))
  15      _parso_path = sys.argv[1]
  16      # The paths are the directory that jedi and parso lie in.
  17      return {'jedi': _jedi_path, 'parso': _parso_path}
  18  
  19  
  20  class _ExactImporter(MetaPathFinder):
  21      def __init__(self, path_dct):
  22          self._path_dct = path_dct
  23  
  24      def find_spec(self, fullname, path=None, target=None):
  25          if path is None and fullname in self._path_dct:
  26              p = self._path_dct[fullname]
  27              spec = PathFinder.find_spec(fullname, path=[p], target=target)
  28              return spec
  29          return None
  30  
  31  
  32  # Try to import jedi/parso.
  33  sys.meta_path.insert(0, _ExactImporter(_get_paths()))
  34  from jedi.inference.compiled import subprocess  # noqa: E402
  35  sys.meta_path.pop(0)
  36  
  37  # Retrieve the pickle protocol.
  38  host_sys_version = [int(x) for x in sys.argv[2].split('.')]
  39  # And finally start the client.
  40  subprocess.Listener().listen()
  41