def seed_cache( options, # type: Namespace pex, # type: PEX ): # type: (...) -> Iterable[str] pex_path = pex.path() with TRACER.timed("Seeding local caches for {}".format(pex_path)): if options.unzip: unzip_dir = pex.pex_info().unzip_dir if unzip_dir is None: raise AssertionError( "Expected PEX-INFO for {} to have the components of an unzip directory" .format(pex_path)) with atomic_directory(unzip_dir, exclusive=True) as chroot: if chroot: with TRACER.timed("Extracting {}".format(pex_path)): with open_zip(options.pex_name) as pex_zip: pex_zip.extractall(chroot) return [pex.interpreter.binary, unzip_dir] elif options.venv: with TRACER.timed("Creating venv from {}".format(pex_path)): venv_pex = ensure_venv(pex) return [venv_pex] else: with TRACER.timed( "Extracting code and distributions for {}".format( pex_path)): pex.activate() return [os.path.abspath(options.pex_name)]
def create( cls, path, # type: str interpreter=None, # type: Optional[PythonInterpreter] ): # type: (...) -> Pip """Creates a pip tool with PEX isolation at path. :param path: The path to assemble the pip tool at. :param interpreter: The interpreter to run Pip with. The current interpreter by default. :return: The path of a PEX that can be used to execute Pip in isolation. """ pip_interpreter = interpreter or PythonInterpreter.get() pip_pex_path = os.path.join(path, isolated().pex_hash) with atomic_directory(pip_pex_path, exclusive=True) as chroot: if not chroot.is_finalized: from pex.pex_builder import PEXBuilder isolated_pip_builder = PEXBuilder(path=chroot.work_dir) isolated_pip_builder.info.venv = True for dist_location in third_party.expose( ["pip", "setuptools", "wheel"]): isolated_pip_builder.add_dist_location(dist=dist_location) isolated_pip_builder.set_script("pip") isolated_pip_builder.freeze() pex_info = PexInfo.from_pex(pip_pex_path) pex_info.add_interpreter_constraint( str(pip_interpreter.identity.requirement)) return cls( ensure_venv( PEX(pip_pex_path, interpreter=pip_interpreter, pex_info=pex_info)))
def seed_cache( options, # type: Namespace pex, # type: PEX verbose=False, # type : bool ): # type: (...) -> str pex_path = pex.path() with TRACER.timed("Seeding local caches for {}".format(pex_path)): pex_info = pex.pex_info() def create_verbose_info(final_pex_path): # type: (str) -> Dict[str, str] return dict(pex_root=pex_info.pex_root, python=pex.interpreter.binary, pex=final_pex_path) if options.unzip: unzip_dir = pex_info.unzip_dir if unzip_dir is None: raise AssertionError( "Expected PEX-INFO for {} to have the components of an unzip directory" .format(pex_path)) with atomic_directory(unzip_dir, exclusive=True) as chroot: if not chroot.is_finalized: with TRACER.timed("Extracting {}".format(pex_path)): with open_zip(options.pex_name) as pex_zip: pex_zip.extractall(chroot.work_dir) if verbose: return json.dumps( create_verbose_info(final_pex_path=unzip_dir)) else: return "{} {}".format(pex.interpreter.binary, unzip_dir) elif options.venv: with TRACER.timed("Creating venv from {}".format(pex_path)): venv_pex = ensure_venv(pex) if verbose: return json.dumps( create_verbose_info(final_pex_path=venv_pex)) else: return venv_pex else: with TRACER.timed( "Extracting code and distributions for {}".format( pex_path)): pex.activate() pex_path = os.path.abspath(options.pex_name) if verbose: return json.dumps(create_verbose_info(final_pex_path=pex_path)) else: return pex_path