def test_from_env(): # type: () -> None with temporary_dir() as td: pex_root = os.path.realpath(os.path.join(td, "pex_root")) environ = dict( PEX_ROOT=pex_root, PEX_MODULE="entry:point", PEX_SCRIPT="script.sh", PEX_FORCE_LOCAL="true", PEX_UNZIP="true", PEX_INHERIT_PATH="prefer", PEX_IGNORE_ERRORS="true", PEX_ALWAYS_CACHE="true", ) info = dict( pex_root=pex_root, entry_point="entry:point", script="script.sh", zip_safe=False, unzip=True, inherit_path=True, ignore_errors=True, always_write_cache=True, ) assert_same_info(PexInfo(info=info), PexInfo.from_env(env=Variables(environ=environ)))
def __init__(self, pex=sys.argv[0], interpreter=None, env=ENV, verify_entry_point=False): self._pex = pex self._interpreter = interpreter or PythonInterpreter.get() self._pex_info = PexInfo.from_pex(self._pex) self._pex_info_overrides = PexInfo.from_env(env=env) self._vars = env self._envs = [] self._working_set = None if verify_entry_point: self._do_entry_point_verification()
def main( pex=None, # type: Optional[PEX] pex_prog_path=None, # type: Optional[str] ): # type: (...) -> int logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO) with TRACER.timed("Executing PEX_TOOLS"): pex_prog_path = simplify_pex_path(pex_prog_path or pex.path()) if pex else None prog = ("PEX_TOOLS=1 {pex_path}".format( pex_path=pex_prog_path) if pex else "{python} {module}".format( python=sys.executable, module=".".join(__name__.split(".")[:-1]))) parser = ArgumentParser( prog=prog, description="Tools for working with {}.".format( pex_prog_path if pex else "PEX files"), ) if pex is None: parser.add_argument("pex", nargs=1, metavar="PATH", help="The path of the PEX file to operate on.") parser.set_defaults(func=functools.partial(show_help, parser)) subparsers = parser.add_subparsers( description= "{} can be operated on using any of the following subcommands.". format("The PEX file {}".format(pex_prog_path ) if pex else "A PEX file"), ) for command in commands.all_commands(): name = command.__class__.__name__.lower() # N.B.: We want to trigger the default argparse description if the doc string is empty. description = command.__doc__ or None help_text = description.splitlines()[0] if description else None command_parser = subparsers.add_parser(name, help=help_text, description=description) command.add_arguments(command_parser) command_parser.set_defaults(func=command.run) options = parser.parse_args() if pex is None: pex_info = PexInfo.from_pex(options.pex[0]) pex_info.update(PexInfo.from_env()) interpreter = pex_bootstrapper.find_compatible_interpreter( interpreter_constraints=pex_info.interpreter_constraints) pex = PEX(options.pex[0], interpreter=interpreter) func = cast("CommandFunc", options.func) result = func(pex, options) result.maybe_display() return result.exit_code
def __init__( self, pex=sys.argv[0], # type: str interpreter=None, # type: Optional[PythonInterpreter] env=ENV, # type: Variables verify_entry_point=False, # type: bool ): # type: (...) -> None self._pex = pex self._interpreter = interpreter or PythonInterpreter.get() self._pex_info = PexInfo.from_pex(self._pex) self._pex_info_overrides = PexInfo.from_env(env=env) self._vars = env self._envs = [] # type: List[PEXEnvironment] self._activated_dists = None # type: Optional[Iterable[Distribution]] if verify_entry_point: self._do_entry_point_verification()
def test_from_env(): environ = dict(PEX_ROOT='/pex_root', PEX_MODULE='entry:point', PEX_SCRIPT='script.sh', PEX_FORCE_LOCAL='true', PEX_INHERIT_PATH='true', PEX_IGNORE_ERRORS='true', PEX_ALWAYS_CACHE='true') info = dict(pex_root='/pex_root', entry_point='entry:point', script='script.sh', zip_safe=False, inherit_path=True, ignore_errors=True, always_write_cache=True) assert_same_info(PexInfo(info=info), PexInfo.from_env(env=Variables(environ=environ)))
def test_from_env(): pex_root = os.path.realpath('/pex_root') environ = dict(PEX_ROOT=pex_root, PEX_MODULE='entry:point', PEX_SCRIPT='script.sh', PEX_FORCE_LOCAL='true', PEX_INHERIT_PATH='true', PEX_IGNORE_ERRORS='true', PEX_ALWAYS_CACHE='true') info = dict(pex_root=pex_root, entry_point='entry:point', script='script.sh', zip_safe=False, inherit_path=True, ignore_errors=True, always_write_cache=True) assert_same_info(PexInfo(info=info), PexInfo.from_env(env=Variables(environ=environ)))
def test_from_empty_env(): environ = Variables(environ={}) info = {} assert_same_info(PexInfo(info=info), PexInfo.from_env(env=environ))
def _bootstrap(entry_point): # type: (str) -> PexInfo pex_info = PexInfo.from_pex(entry_point) # type: PexInfo pex_info.update(PexInfo.from_env()) pex_warnings.configure_warnings(pex_info, ENV) return pex_info
def test_from_empty_env(): # type: () -> None environ = Variables(environ={}) info = {} # type: Dict assert_same_info(PexInfo(info=info), PexInfo.from_env(env=environ))