MCPcopy
hub / github.com/pex-tool/pex / _spawn_from_binary_external

Method _spawn_from_binary_external

pex/interpreter.py:1094–1176  ·  view source on GitHub ↗
(
        cls,
        binary,  # type: str
        ignore_cached=False,  # type: bool
    )

Source from the content-addressed store, hash-verified

1092
1093 @classmethod
1094 def _spawn_from_binary_external(
1095 cls,
1096 binary, # type: str
1097 ignore_cached=False, # type: bool
1098 ):
1099 # type: (...) -> SpawnedJob[PythonInterpreter]
1100
1101 def create_interpreter(
1102 stdout, # type: bytes
1103 check_binary=False, # type: bool
1104 ):
1105 # type: (...) -> PythonInterpreter
1106 identity = stdout.decode("utf-8").strip()
1107 if not identity:
1108 raise cls.IdentificationError("Could not establish identity of {}.".format(binary))
1109 interpreter = cls(PythonIdentity.decode(identity))
1110 # We should not need to check this since binary == interpreter.binary should always be
1111 # true, but historically this could be untrue as noted in `PythonIdentity.get`.
1112 if check_binary and not os.path.exists(interpreter.binary):
1113 raise cls.InterpreterNotFound(
1114 "Cached interpreter for {} reports a binary of {}, which could not be found".format(
1115 binary, interpreter.binary
1116 )
1117 )
1118 return interpreter
1119
1120 cache_dir = InterpreterDir.create(binary)
1121 if ignore_cached:
1122 safe_rmtree(cache_dir)
1123 if os.path.isfile(cache_dir.interp_info_file):
1124 try:
1125 with open(cache_dir.interp_info_file, "rb") as fp:
1126 return SpawnedJob.completed(create_interpreter(fp.read(), check_binary=True))
1127 except (IOError, OSError, cls.Error, PythonIdentity.Error):
1128 safe_rmtree(cache_dir)
1129 return cls._spawn_from_binary_external(binary)
1130 else:
1131 pythonpath = tuple(third_party.expose(["pex"]))
1132 cmd, env = cls._create_isolated_cmd(
1133 binary,
1134 args=[
1135 "-c",
1136 dedent(
1137 """\
1138 from __future__ import absolute_import
1139
1140 import os
1141 import sys
1142
1143 from pex import interpreter
1144 from pex.atomic_directory import atomic_directory
1145 from pex.common import safe_open
1146 from pex.interpreter import PythonIdentity
1147
1148
1149 with interpreter.path_mappings({path_mappings!r}):
1150 encoded_identity = PythonIdentity.get(binary={binary!r}).encode()
1151 with atomic_directory({cache_dir!r}) as cache_dir:

Callers 1

_spawn_from_binaryMethod · 0.80

Calls 10

safe_rmtreeFunction · 0.90
safe_mkdtempFunction · 0.90
JobClass · 0.90
completedMethod · 0.80
_create_isolated_cmdMethod · 0.80
fileMethod · 0.80
createMethod · 0.45
readMethod · 0.45
exposeMethod · 0.45
open_processMethod · 0.45

Tested by

no test coverage detected