def run( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result if options.indent and not options.verbose: logger.warning( "Ignoring --indent={} since --verbose mode is not enabled.". format(options.indent)) with self.output(options) as out: try: for interpreter in self._find_interpreters(pex, all=options.all): if options.verbose: self.dump_json( options, { "path": interpreter.binary, "requirement": str(interpreter.identity.requirement), "platform": str(interpreter.platform), }, out, ) else: out.write(interpreter.binary) out.write("\n") except UnsatisfiableInterpreterConstraintsError as e: return Error(str(e)) return Ok()
def run( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result venv_dir = options.venv[0] venv = Virtualenv.create(venv_dir, interpreter=pex.interpreter, force=options.force, copies=options.copies) populate_venv_with_pex( venv, pex, bin_path=BinPath.for_value(options.bin_path), collisions_ok=options.collisions_ok, ) if options.pip: try: venv.install_pip() except PipUnavailableError as e: return Error( "The virtual environment was successfully created, but Pip was not " "installed:\n{}".format(e)) if options.compile: pex.interpreter.execute(["-m", "compileall", venv_dir]) return Ok()
def _extract( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result if not options.serve and not options.dest_dir: return Error("Specify a --find-links directory to extract wheels to.") dest_dir = ( os.path.abspath(os.path.expanduser(options.dest_dir)) if options.dest_dir else safe_mkdtemp() ) safe_mkdir(dest_dir) if options.sources: self._extract_sdist(pex, dest_dir) def spawn_extract(distribution): # type: (Distribution) -> SpawnedJob[Text] job = spawn_python_job( args=["-m", "wheel", "pack", "--dest-dir", dest_dir, distribution.location], interpreter=pex.interpreter, expose=["wheel"], stdout=subprocess.PIPE, ) return SpawnedJob.stdout( job, result_func=lambda out: "{}: {}".format(distribution, out.decode()) ) with self._distributions_output(pex, options) as (distributions, output): errors = [] for result in execute_parallel(distributions, spawn_extract, error_handler=Retain()): if isinstance(result, tuple): distribution, error = result errors.append(distribution) output.write( "Failed to build a wheel for {distribution}: {error}\n".format( distribution=distribution, error=error ) ) else: output.write(result) if errors: return Error( "Failed to build wheels for {count} {distributions}.".format( count=len(errors), distributions=pluralize(errors, "distribution") ) ) if not options.serve: return Ok() repo = FindLinksRepo.serve( interpreter=pex.interpreter, port=options.port, directory=dest_dir ) output.write( "Serving find-links repo of {pex} via {find_links} at http://localhost:{port}\n".format( pex=os.path.normpath(pex.path()), find_links=dest_dir, port=repo.port ) ) if options.pid_file: with safe_open(options.pid_file, "w") as fp: fp.write("{}:{}".format(repo.pid, repo.port)) try: return Result(exit_code=repo.join(), message=" ".join(repo.cmd)) except KeyboardInterrupt: repo.kill() return Ok("Shut down server for find links repo at {}.".format(dest_dir))