def peek(self): config.remove_override("quiet") new_context = ResolvedContext(self.context.requested_packages(), package_paths=self.context.package_paths) # reapply quiet mode (see cli.forward) if "REZ_QUIET" not in os.environ: config.override("quiet", True) self.context.print_resolve_diff(new_context) return 0
def _run(self, prefix_char, args): import argparse parser = argparse.ArgumentParser(prog=self.tool_name, prefix_chars=prefix_char) def _add_argument(*nargs, **kwargs): nargs_ = [] for narg in nargs: nargs_.append(narg.replace('=', prefix_char)) parser.add_argument(*nargs_, **kwargs) _add_argument("=a", "==about", action="store_true", help="print information about the tool") _add_argument( "=i", "==interactive", action="store_true", help="launch an interactive shell within the tool's configured " "environment") _add_argument("=p", "==patch", type=str, nargs='*', metavar="PKG", help="run the tool in a patched environment") _add_argument("==versions", action="store_true", help="list versions of package providing this tool") _add_argument( "==command", type=str, nargs='+', metavar=("COMMAND", "ARG"), help="read commands from string, rather than executing the tool") _add_argument( "==stdin", action="store_true", help= "read commands from standard input, rather than executing the tool" ) _add_argument( "==strict", action="store_true", help="strict patching. Ignored if ++patch is not present") _add_argument("==nl", "==no-local", dest="no_local", action="store_true", help="don't load local packages when patching") _add_argument( "==peek", action="store_true", help="diff against the tool's context and a re-resolved copy - " "this shows how 'stale' the context is") _add_argument("==verbose", action="count", default=0, help="verbose mode, repeat for more verbosity") _add_argument( "==quiet", action="store_true", help="hide welcome message when entering interactive mode") _add_argument( "==no-rez-args", dest="no_rez_args", action="store_true", help="pass all args to the tool, even if they start with '%s'" % prefix_char) opts, tool_args = parser.parse_known_args(args) if opts.no_rez_args: args = list(args) args.remove("==no-rez-args".replace('=', prefix_char)) tool_args = args opts = parser.parse_args([]) # print info if opts.about: return self.print_about() elif opts.versions: return self.print_package_versions() elif opts.peek: return self.peek() # patching context = self.context if opts.patch is not None: new_request = opts.patch request = context.get_patched_request(new_request, strict=opts.strict) config.remove_override("quiet") pkg_paths = (config.nonlocal_packages_path if opts.no_local else None) context = ResolvedContext(request, package_paths=pkg_paths, verbosity=opts.verbose) # reapply quiet mode (see cli.forward) if "REZ_QUIET" not in os.environ: config.override("quiet", True) if opts.stdin: # generally shells will behave as though the '-s' flag was not present # when no stdin is available. So here we replicate this behaviour. import select try: if not select.select([sys.stdin], [], [], 0.0)[0]: opts.stdin = False except select.error: pass # because windows # construct command cmd = None if opts.command: cmd = opts.command elif opts.interactive: label = self.context_name if opts.patch: label += '*' config.override("prompt", "%s>" % label) cmd = None else: cmd = [self.tool_name] + tool_args retcode, _, _ = context.execute_shell(command=cmd, stdin=opts.stdin, quiet=opts.quiet, block=True) return retcode
def _run(self, prefix_char, args): from rez.vendor import argparse parser = argparse.ArgumentParser(prog=self.tool_name, prefix_chars=prefix_char) def _add_argument(*nargs, **kwargs): nargs_ = [] for narg in nargs: nargs_.append(narg.replace('=', prefix_char)) parser.add_argument(*nargs_, **kwargs) _add_argument( "=a", "==about", action="store_true", help="print information about the tool") _add_argument( "=i", "==interactive", action="store_true", help="launch an interactive shell within the tool's configured " "environment") _add_argument( "=p", "==patch", type=str, nargs='*', metavar="PKG", help="run the tool in a patched environment") _add_argument( "==versions", action="store_true", help="list versions of package providing this tool") _add_argument( "==command", type=str, nargs='+', metavar=("COMMAND", "ARG"), help="read commands from string, rather than executing the tool") _add_argument( "==stdin", action="store_true", help="read commands from standard input, rather than executing the tool") _add_argument( "==strict", action="store_true", help="strict patching. Ignored if ++patch is not present") _add_argument( "==nl", "==no-local", dest="no_local", action="store_true", help="don't load local packages when patching") _add_argument( "==peek", action="store_true", help="diff against the tool's context and a re-resolved copy - " "this shows how 'stale' the context is") _add_argument( "==verbose", action="count", default=0, help="verbose mode, repeat for more verbosity") _add_argument( "==quiet", action="store_true", help="hide welcome message when entering interactive mode") _add_argument( "==no-rez-args", dest="no_rez_args", action="store_true", help="pass all args to the tool, even if they start with '%s'" % prefix_char) opts, tool_args = parser.parse_known_args(args) if opts.no_rez_args: args = list(args) args.remove("==no-rez-args".replace('=', prefix_char)) tool_args = args opts = parser.parse_args([]) # print info if opts.about: return self.print_about() elif opts.versions: return self.print_package_versions() elif opts.peek: return self.peek() # patching context = self.context if opts.patch is not None: new_request = opts.patch request = context.get_patched_request(new_request, strict=opts.strict) config.remove_override("quiet") pkg_paths = (config.nonlocal_packages_path if opts.no_local else None) context = ResolvedContext(request, package_paths=pkg_paths, verbosity=opts.verbose) # reapply quiet mode (see cli.forward) if "REZ_QUIET" not in os.environ: config.override("quiet", True) if opts.stdin: # generally shells will behave as though the '-s' flag was not present # when no stdin is available. So here we replicate this behaviour. import select if not select.select([sys.stdin], [], [], 0.0)[0]: opts.stdin = False # construct command cmd = None if opts.command: cmd = opts.command elif opts.interactive: label = self.context_name if opts.patch: label += '*' config.override("prompt", "%s>" % label) cmd = None else: cmd = [self.tool_name] + tool_args retcode, _, _ = context.execute_shell(command=cmd, stdin=opts.stdin, quiet=opts.quiet, block=True) return retcode