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 run( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result graph = self._create_dependency_graph(pex) if not (options.render or options.open): with self.output(options) as out: graph.emit(out) return Ok() if not options.open: with self.output(options, binary=True) as out: return self._dot(options, graph, out) with self._output_for_open(options) as (out, open_path): result = self._dot(options, graph, out) if result.is_error: return result return try_open_file( open_path, error= "Failed to open dependency graph of {} rendered in {} for viewing." .format(pex.path(), open_path), )
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 _info( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result with self._distributions_output(pex, options) as (distributions, output): for distribution in distributions: if options.verbose: requires_python = dist_metadata.requires_python(distribution) requires_dists = list(dist_metadata.requires_dists(distribution)) self.dump_json( options, dict( project_name=distribution.project_name, version=distribution.version, requires_python=str(requires_python) if requires_python else None, requires_dists=[str(dist) for dist in requires_dists], location=distribution.location, ), output, ) else: output.write( "{project_name} {version} {location}".format( project_name=distribution.project_name, version=distribution.version, location=distribution.location, ) ) output.write("\n") return Ok()
def run( self, pex, # type: PEX options, # type: Namespace ): # type: (...) -> Result with self.output(options) as out: self.dump_json(options, pex.pex_info().as_json_dict(), out) out.write("\n") 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))