Пример #1
0
    def _get_subprocess(self):
        if self._subprocess is not None and not self._subprocess.is_crashed:
            return self._subprocess

        try:
            self._subprocess = CompiledSubprocess(self._start_executable)
            info = self._subprocess._send(None, _get_info)
        except Exception as exc:
            raise InvalidPythonEnvironment(
                "Could not get version information for %r: %r" % (
                    self._start_executable,
                    exc))

        # Since it could change and might not be the same(?) as the one given,
        # set it here.
        self.executable = info[0]
        """
        The Python executable, matches ``sys.executable``.
        """
        self.path = info[1]
        """
        The path to an environment, matches ``sys.prefix``.
        """
        self.version_info = _VersionInfo(*info[2])
        """
        Like ``sys.version_info``. A tuple to show the current Environment's
        Python version.
        """

        # py2 sends bytes via pickle apparently?!
        if self.version_info.major == 2:
            self.executable = self.executable.decode()
            self.path = self.path.decode()

        # Adjust pickle protocol according to host and client version.
        self._subprocess._pickle_protocol = highest_pickle_protocol([
            sys.version_info, self.version_info])

        return self._subprocess
Пример #2
0
    def _get_subprocess(self):
        if self._subprocess is not None and not self._subprocess.is_crashed:
            return self._subprocess

        try:
            self._subprocess = CompiledSubprocess(self._start_executable)
            info = self._subprocess._send(None, _get_info)
        except Exception as exc:
            raise InvalidPythonEnvironment(
                "Could not get version information for %r: %r" % (
                    self._start_executable,
                    exc))

        # Since it could change and might not be the same(?) as the one given,
        # set it here.
        self.executable = info[0]
        """
        The Python executable, matches ``sys.executable``.
        """
        self.path = info[1]
        """
        The path to an environment, matches ``sys.prefix``.
        """
        self.version_info = _VersionInfo(*info[2])
        """
        Like ``sys.version_info``. A tuple to show the current Environment's
        Python version.
        """

        # py2 sends bytes via pickle apparently?!
        if self.version_info.major == 2:
            self.executable = self.executable.decode()
            self.path = self.path.decode()

        # Adjust pickle protocol according to host and client version.
        self._subprocess._pickle_protocol = highest_pickle_protocol([
            sys.version_info, self.version_info])

        return self._subprocess
Пример #3
0
def test_highest_pickle_protocol():
    v = namedtuple('version', 'major, minor')
    assert highest_pickle_protocol([v(2, 7), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 8)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 5)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 6)]) == 2
    assert highest_pickle_protocol([v(3, 8), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(3, 8), v(3, 8)]) == 4
    assert highest_pickle_protocol([v(3, 8), v(3, 5)]) == 4
    assert highest_pickle_protocol([v(3, 8), v(3, 6)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(3, 6), v(3, 8)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(3, 5)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(3, 6)]) == 4
Пример #4
0
            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

    # Try to import jedi/parso.
    sys.meta_path.insert(0, _ExactImporter(_get_paths()))
    from jedi.evaluate.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.evaluate.compiled import subprocess  # NOQA

from jedi._compatibility import highest_pickle_protocol  # noqa: E402


# Retrieve the pickle protocol.
host_sys_version = [int(x) for x in sys.argv[2].split('.')]
pickle_protocol = highest_pickle_protocol([sys.version_info, host_sys_version])
# And finally start the client.
subprocess.Listener(pickle_protocol=pickle_protocol).listen()
Пример #5
0
        def find_module(self, fullname, path=None):
            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

    # Try to import jedi/parso.
    sys.meta_path.insert(0, _ExactImporter(_get_paths()))
    from jedi.evaluate.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.evaluate.compiled import subprocess  # NOQA

from jedi._compatibility import highest_pickle_protocol  # noqa: E402

# Retrieve the pickle protocol.
host_sys_version = [int(x) for x in sys.argv[2].split('.')]
pickle_protocol = highest_pickle_protocol([sys.version_info, host_sys_version])
# And finally start the client.
subprocess.Listener(pickle_protocol=pickle_protocol).listen()
Пример #6
0
 def __init__(self, executable, version):
     self._executable = executable
     self._evaluator_deletion_queue = queue.deque()
     self._pickle_protocol = highest_pickle_protocol(
         [sys.version_info, version])
Пример #7
0
def test_highest_pickle_protocol():
    v = namedtuple('version', 'major, minor')
    assert highest_pickle_protocol([v(2, 7), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 3)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 4)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 5)]) == 2
    assert highest_pickle_protocol([v(2, 7), v(3, 6)]) == 2
    assert highest_pickle_protocol([v(3, 3), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(3, 3), v(3, 3)]) == 3
    assert highest_pickle_protocol([v(3, 3), v(3, 4)]) == 3
    assert highest_pickle_protocol([v(3, 3), v(3, 5)]) == 3
    assert highest_pickle_protocol([v(3, 3), v(3, 6)]) == 3
    assert highest_pickle_protocol([v(3, 4), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(3, 4), v(3, 3)]) == 3
    assert highest_pickle_protocol([v(3, 4), v(3, 4)]) == 4
    assert highest_pickle_protocol([v(3, 4), v(3, 5)]) == 4
    assert highest_pickle_protocol([v(3, 4), v(3, 6)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(2, 7)]) == 2
    assert highest_pickle_protocol([v(3, 6), v(3, 3)]) == 3
    assert highest_pickle_protocol([v(3, 6), v(3, 4)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(3, 5)]) == 4
    assert highest_pickle_protocol([v(3, 6), v(3, 6)]) == 4