| 218 | |
| 219 | @classmethod |
| 220 | def mount( |
| 221 | cls, |
| 222 | pex, # type: str |
| 223 | pex_info=None, # type: Optional[PexInfo] |
| 224 | target=None, # type: Optional[Target] |
| 225 | ): |
| 226 | # type: (...) -> PEXEnvironment |
| 227 | pex_file = os.path.realpath(pex) |
| 228 | if not pex_info: |
| 229 | pex_info = PexInfo.from_pex(pex_file) |
| 230 | pex_info.update(PexInfo.from_env()) |
| 231 | pex_hash = pex_info.pex_hash |
| 232 | if pex_hash is None: |
| 233 | raise AssertionError( |
| 234 | "There was no pex_hash stored in {} for {}.".format(PexInfo.PATH, pex) |
| 235 | ) |
| 236 | target = target or targets.current() |
| 237 | key = (pex_file, pex_hash, target) |
| 238 | mounted = cls._CACHE.get(key) |
| 239 | if mounted is None: |
| 240 | pex_root = pex_info.pex_root |
| 241 | installed_pex = ensure_installed(pex=pex, pex_root=pex_root, pex_hash=pex_hash) |
| 242 | mounted = cls(pex=installed_pex, pex_info=pex_info, target=target, source_pex=pex) |
| 243 | cls._CACHE[key] = mounted |
| 244 | return mounted |
| 245 | |
| 246 | def __init__( |
| 247 | self, |