Example #1
0
def setup_parser(parser, completions=False):
    from rez.shells import get_shell_types
    from rez.system import system

    formats = get_shell_types() + ['dict', 'table']

    parser.add_argument(
        "-f", "--format", type=str, choices=formats,
        help="print output in the given format. If None, the current shell "
        "language (%s) is used" % system.shell)
    parser.add_argument(
        "--no-env", dest="no_env", action="store_true",
        help="interpret the code in an empty environment")
    pv_action = parser.add_argument(
        "--pv", "--parent-variables", dest="parent_vars", type=str,
        metavar='VAR', nargs='+',
        help="environment variables to update rather than overwrite on first "
        "reference. If this is set to the special value 'all', all variables "
        "will be treated this way")
    FILE_action = parser.add_argument(
        "FILE", type=str,
        help='file containing rex code to execute')

    if completions:
        from rez.cli._complete_util import FilesCompleter
        from rez.vendor.argcomplete.completers import EnvironCompleter
        pv_action.completer = EnvironCompleter
        FILE_action.completer = FilesCompleter(dirs=False,
                                               file_patterns=["*.py", "*.rex"])
Example #2
0
 def wrapper(self, *args, **kwargs):
     for shell in get_shell_types():
         if exclude and shell in exclude:
             self.skipTest("This test does not run on %s shell." % shell)
         print "\ntesting in shell: %s..." % shell
         config.override("default_shell", shell)
         func(self, *args, **kwargs)
Example #3
0
def setup_parser(parser, completions=False):
    from rez.shells import get_shell_types
    from rez.system import system

    formats = get_shell_types() + ['dict', 'table']

    parser.add_argument(
        "-f", "--format", type=str, choices=formats,
        help="print output in the given format. If None, the current shell "
        "language (%s) is used" % system.shell)
    parser.add_argument(
        "--no-env", dest="no_env", action="store_true",
        help="interpret the code in an empty environment")
    pv_action = parser.add_argument(
        "--pv", "--parent-variables", dest="parent_vars", type=str,
        metavar='VAR', nargs='+',
        help="environment variables to update rather than overwrite on first "
        "reference. If this is set to the special value 'all', all variables "
        "will be treated this way")
    FILE_action = parser.add_argument(
        "FILE", type=str,
        help='file containing rex code to execute')

    if completions:
        from rez.cli._complete_util import FilesCompleter
        from rez.vendor.argcomplete.completers import EnvironCompleter
        pv_action.completer = EnvironCompleter
        FILE_action.completer = FilesCompleter(dirs=False,
                                               file_patterns=["*.py", "*.rex"])
Example #4
0
        def wrapper(self, *args, **kwargs):
            shells = get_shell_types()

            only_shell = os.getenv("__REZ_SELFTEST_SHELL")
            if only_shell:
                shells = [only_shell]

            # filter to only those shells available
            shells = [x for x in shells if get_shell_class(x).is_available()]

            for shell in shells:
                print("\ntesting in shell: %s..." % shell)
                config.override("default_shell", shell)

                try:
                    func(self, *args, **kwargs)
                except Exception as e:
                    # Add the shell to the exception message, if possible.
                    # In some IDEs the args do not exist at all.
                    if hasattr(e, "args") and e.args:
                        try:
                            args = list(e.args)
                            args[0] = str(
                                args[0]) + " (in shell '{}')".format(shell)
                            e.args = tuple(args)
                        except:
                            raise e
                    raise
Example #5
0
File: util.py Project: mottosso/rez
        def wrapper(self, *args, **kwargs):
            shells = get_shell_types()
            only_shell = os.getenv("__REZ_SELFTEST_SHELL")
            if only_shell:
                shells = [only_shell]

            for shell in shells:
                if exclude and shell in exclude:
                    self.skipTest("This test does not run on %s shell." % shell)
                print "\ntesting in shell: %s..." % shell
                config.override("default_shell", shell)
                func(self, *args, **kwargs)
Example #6
0
        def wrapper(self, *args, **kwargs):
            shells = get_shell_types()
            only_shell = os.getenv("__REZ_SELFTEST_SHELL")
            if only_shell:
                shells = [only_shell]

            for shell in shells:
                if exclude and shell in exclude:
                    self.skipTest("This test does not run on %s shell." % shell)
                print "\ntesting in shell: %s..." % shell
                config.override("default_shell", shell)
                func(self, *args, **kwargs)
Example #7
0
    def __init__(self, context_model=None, parent=None):
        super(ContextDetailsWidget, self).__init__(parent)
        ContextViewMixin.__init__(self, context_model)
        self.code_pending = True

        self.overview_edit = StreamableTextEdit()
        self.overview_edit.setStyleSheet("font: 12pt 'Courier'")

        self.graph_btn = ViewGraphButton(context_model)
        btn_pane = create_pane([None, self.graph_btn], True)
        overview_pane = create_pane([self.overview_edit, btn_pane], False)

        self.code_edit = SearchableTextEdit()
        self.code_edit.setStyleSheet("font: 12pt 'Courier'")

        self.code_combo = QtWidgets.QComboBox()
        # strip out 'sh' and 'csh', they only differ from bash and tcsh in shell
        # startup behaviour, which is irrelevant here
        code_types = set(get_shell_types()) - set([system.shell, "sh", "csh"])
        code_types = [system.shell] + sorted(code_types) + ["python dict"]
        for code_type in code_types:
            self.code_combo.addItem(code_type)

        label = QtWidgets.QLabel("Format:")
        btn_pane = create_pane([None, label, self.code_combo], True)
        code_pane = create_pane([self.code_edit, btn_pane], False)

        self.environ_widget = ContextEnvironWidget()

        self.addTab(overview_pane, "overview")
        self.addTab(code_pane, "shell code")
        self.addTab(self.environ_widget, "environment")

        self.code_combo.currentIndexChanged.connect(self._update_code)
        self.currentChanged.connect(self._currentTabChanged)

        self.refresh()
    def __init__(self, context_model=None, parent=None):
        super(ContextDetailsWidget, self).__init__(parent)
        ContextViewMixin.__init__(self, context_model)
        self.code_pending = True

        self.overview_edit = StreamableTextEdit()
        self.overview_edit.setStyleSheet("font: 9pt 'Courier'")

        self.graph_btn = ViewGraphButton(context_model)
        btn_pane = create_pane([None, self.graph_btn], True)
        overview_pane = create_pane([self.overview_edit, btn_pane], False)

        self.code_edit = SearchableTextEdit()
        self.code_edit.setStyleSheet("font: 9pt 'Courier'")

        self.code_combo = QtGui.QComboBox()
        # strip out 'sh' and 'csh', they only differ from bash and tcsh in shell
        # startup behaviour, which is irrelevant here
        code_types = set(get_shell_types()) - set([system.shell, "sh", "csh"])
        code_types = [system.shell] + sorted(code_types) + ["python dict"]
        for code_type in code_types:
            self.code_combo.addItem(code_type)

        label = QtGui.QLabel("Format:")
        btn_pane = create_pane([None, label, self.code_combo], True)
        code_pane = create_pane([self.code_edit, btn_pane], False)

        self.environ_widget = ContextEnvironWidget()

        self.addTab(overview_pane, "overview")
        self.addTab(code_pane, "shell code")
        self.addTab(self.environ_widget, "environment")

        self.code_combo.currentIndexChanged.connect(self._update_code)
        self.currentChanged.connect(self._currentTabChanged)

        self.refresh()
Example #9
0
def setup_parser(parser, completions=False):
    from rez.system import system
    from rez.shells import get_shell_types

    formats = get_shell_types() + ['dict', 'table']
    if json is not None:
        formats.append('json')

    output_styles = [e.name for e in OutputStyle]

    parser.add_argument(
        "--req",
        "--print-request",
        dest="print_request",
        action="store_true",
        help="print only the request list (not including implicits)")
    parser.add_argument("--res",
                        "--print-resolve",
                        dest="print_resolve",
                        action="store_true",
                        help="print only the resolve list")
    parser.add_argument(
        "--so",
        "--source-order",
        dest="source_order",
        action="store_true",
        help="print resolved packages in order they are sorted, rather than "
        "alphabetical order")
    parser.add_argument(
        "--su",
        "--show-uris",
        dest="show_uris",
        action="store_true",
        help="list resolved package's URIs, rather than the default 'root' "
        "filepath")
    parser.add_argument(
        "-t",
        "--tools",
        action="store_true",
        help="print a list of the executables available in the context")
    parser.add_argument("--which",
                        type=str,
                        metavar="CMD",
                        help="locate a program within the context")
    parser.add_argument("-g",
                        "--graph",
                        action="store_true",
                        help="display the resolve graph as an image")
    parser.add_argument("--pg",
                        "--print-graph",
                        dest="print_graph",
                        action="store_true",
                        help="print the resolve graph as a string")
    parser.add_argument("--wg",
                        "--write-graph",
                        dest="write_graph",
                        type=str,
                        metavar='FILE',
                        help="write the resolve graph to FILE")
    parser.add_argument("--pp",
                        "--prune-package",
                        dest="prune_pkg",
                        metavar="PKG",
                        type=str,
                        help="prune the graph down to PKG")
    parser.add_argument(
        "-i",
        "--interpret",
        action="store_true",
        help="interpret the context and print the resulting code")
    parser.add_argument(
        "-f",
        "--format",
        type=str,
        choices=formats,
        default=system.shell,
        help="print interpreted output in the given format. Ignored if "
        "--interpret is not present (default: %(default)s). If one of "
        "table, dict or json, the environ dict is printed.")
    parser.add_argument(
        "-s",
        "--style",
        type=str,
        default="file",
        choices=output_styles,
        help="Set code output style. Ignored if --interpret is not present "
        "(default: %(default)s)")
    parser.add_argument("--no-env",
                        dest="no_env",
                        action="store_true",
                        help="interpret the context in an empty environment")
    diff_action = parser.add_argument(
        "--diff",
        type=str,
        metavar="RXT",
        help="diff the current context against the given context")
    parser.add_argument(
        "--fetch",
        action="store_true",
        help="diff the current context against a re-resolved copy of the "
        "current context")
    RXT_action = parser.add_argument(
        "RXT",
        type=str,
        nargs='?',
        help="rez context file (current context if not supplied). Use '-' to "
        "read the context from stdin")

    if completions:
        from rez.cli._complete_util import FilesCompleter
        rxt_completer = FilesCompleter(dirs=False, file_patterns=["*.rxt"])
        RXT_action.completer = rxt_completer
        diff_action.completer = rxt_completer
Example #10
0
    def shell(self):
        """Get the current shell.
        @returns The current shell this process is running in. Examples:

            bash
            tcsh
        """
        from rez.shells import get_shell_types
        shells = set(get_shell_types())
        if not shells:
            raise RezSystemError("no shells available")

        if self.platform == "windows":
            return "cmd"
        else:
            import subprocess as sp
            shell = None

            # check parent process via ps
            try:
                args = ['ps', '-o', 'args=', '-p', str(os.getppid())]
                proc = sp.Popen(args, stdout=sp.PIPE)
                output = proc.communicate()[0]
                shell = os.path.basename(output.strip().split()[0]).replace(
                    '-', '')
            except Exception:
                pass

            # check $SHELL
            if shell not in shells:
                shell = os.path.basename(os.getenv("SHELL", ''))

            # traverse parent procs via /proc/(pid)/status
            if shell not in shells:
                pid = str(os.getppid())
                found = False

                while not found:
                    try:
                        file = os.path.join(os.sep, "proc", pid, "status")
                        with open(file) as f:
                            loc = f.read().split('\n')

                        for line in loc:
                            line = line.strip()
                            toks = line.split()
                            if len(toks) == 2:
                                if toks[0] == "Name:":
                                    name = toks[1]
                                    if name in shells:
                                        shell = name
                                        found = True
                                        break
                                elif toks[0] == "PPid:":
                                    pid = toks[1]
                    except Exception:
                        break

            if (shell not in shells) and ("sh" in shells):
                shell = "sh"  # failed detection, fall back on 'sh'
            elif (shell not in shells) and ("bash" in shells):
                shell = "bash"  # failed detection, fall back on 'bash'
            elif shell not in shells:
                shell = next(iter(shells))  # give up - just choose a shell

            # sh has to be handled as a special case
            if shell == "sh":
                if os.path.islink("/bin/sh"):
                    path = os.readlink("/bin/sh")
                    shell2 = os.path.split(path)[-1]

                    if shell2 == "bash":
                        # bash switches to sh-like shell when invoked as sh,
                        # so we want to use the sh shell plugin
                        pass
                    elif shell2 == "dash":
                        # dash doesn't have an sh emulation mode, so we have
                        # to use the dash shell plugin
                        if "dash" in shells:
                            shell = "dash"
                        else:
                            # this isn't good!
                            if "bash" in shells:
                                shell = "bash"  # fall back on bash
                            else:
                                shell = next(iter(
                                    shells))  # give up - just choose a shell

            # TODO: remove this when/if dash support added
            if shell == "dash":
                shell = "bash"

            return shell
Example #11
0
def setup_parser(parser, completions=False):
    from argparse import SUPPRESS
    from rez.config import config
    from rez.system import system
    from rez.shells import get_shell_types

    shells = get_shell_types()

    parser.add_argument(
        "--shell", dest="shell", type=str, choices=shells,
        default=config.default_shell or system.shell,
        help="target shell type (default: %(default)s)")
    parser.add_argument(
        "--isolated", action="store_true",
        help="Do not inherit the parent environment")
    parser.add_argument(
        "--inherited", action="store_true",
        help="Inherit the parent environment")
    parser.add_argument(
        "--rcfile", type=str,
        help="source this file instead of the target shell's standard startup "
        "scripts, if possible")
    parser.add_argument(
        "--norc", action="store_true",
        help="skip loading of startup scripts")
    command_action = parser.add_argument(
        "-c", "--command", type=str,
        help="read commands from string. Alternatively, list command arguments "
        "after a '--'")
    parser.add_argument(
        "-s", "--stdin", action="store_true",
        help="read commands from standard input")
    parser.add_argument(
        "--ni", "--no-implicit", dest="no_implicit",
        action="store_true",
        help="don't add implicit packages to the request")
    parser.add_argument(
        "--nl", "--no-local", dest="no_local", action="store_true",
        help="don't load local packages")
    parser.add_argument(
        "-b", "--build", action="store_true",
        help="create a build environment")
    parser.add_argument(
        "--paths", type=str, default=None,
        help="set package search path")
    parser.add_argument(
        "-t", "--time", type=str,
        help="ignore packages released after the given time. Supported formats "
        "are: epoch time (eg 1393014494), or relative time (eg -10s, -5m, "
        "-0.5h, -10d)")
    parser.add_argument(
        "--max-fails", type=int, default=-1, dest="max_fails",
        metavar='N',
        help="abort if the number of failed configuration attempts exceeds N")
    parser.add_argument(
        "--time-limit", type=int, default=-1,
        dest="time_limit", metavar='SECS',
        help="abort if the resolve time exceeds SECS")
    parser.add_argument(
        "-o", "--output", type=str, metavar="FILE",
        help="store the context into an rxt file, instead of starting an "
        "interactive shell. Note that this will also store a failed resolve. "
        "If you use the special value '-', the context is written to stdout.")
    input_action = parser.add_argument(
        "-i", "--input", type=str, metavar="FILE",
        help="use a previously saved context. Resolve settings, such as PKG, "
        "--ni etc are ignored in this case")
    parser.add_argument(
        "--exclude", type=str, nargs='+', metavar="RULE",
        help="add package exclusion filters, eg '*.beta'. Note that these are "
        "added to the globally configured exclusions")
    parser.add_argument(
        "-e", "--env", action='append', metavar="KEY=VALUE",
        help="inject a KEY=VALUE pair into the resulting context. "
             "Keeps reading key=value pairs until the next argument is passed")
    parser.add_argument(
        "--include", type=str, nargs='+', metavar="RULE",
        help="add package inclusion filters, eg 'mypkg', 'boost-*'. Note that "
        "these are added to the globally configured inclusions")
    parser.add_argument(
        "--no-filters", dest="no_filters", action="store_true",
        help="turn off package filters. Note that any filters specified with "
        "--exclude/--include are still applied")
    parser.add_argument(
        "-p", "--patch", action="store_true",
        help="patch the current context to create a new context")
    parser.add_argument(
        "--strict", action="store_true",
        help="strict patching. Ignored if --patch is not present")
    parser.add_argument(
        "--patch-rank", type=int, metavar="N", default=0,
        help="patch rank. Ignored if --patch is not present")
    parser.add_argument(
        "--no-cache", dest="no_cache", action="store_true",
        help="do not fetch cached resolves")
    parser.add_argument(
        "-q", "--quiet", action="store_true",
        help="run in quiet mode (hides welcome message)")
    parser.add_argument(
        "--fail-graph", action="store_true",
        help="if the build environment fails to resolve due to a conflict, "
        "display the resolve graph as an image.")
    parser.add_argument(
        "--new-session", action="store_true",
        help="start the shell in a new process group")
    parser.add_argument(
        "--detached", action="store_true",
        help="open a separate terminal")
    parser.add_argument(
        "--no-passive", action="store_true",
        help="only print actions that affect the solve (has an effect only "
        "when verbosity is enabled)")
    parser.add_argument(
        "--self", action="store_true", help=(
            "Include requirement for the version of bleeding-rez "
            "that's being called, useful for gaining access to "
            "rez commands from within a rez context."))
    parser.add_argument(
        "--stats", action="store_true",
        help="print advanced solver stats")
    parser.add_argument(
        "--pre-command", type=str, help=SUPPRESS)
    PKG_action = parser.add_argument(
        "PKG", type=str, nargs='*',
        help='packages to use in the target environment')
    extra_0_action = parser.add_argument(  # args after --
        "--N0", dest="extra_0", nargs='*',
        help=SUPPRESS)

    if completions:
        from rez.cli._complete_util import PackageCompleter, FilesCompleter, \
            ExecutablesCompleter, AndCompleter, SequencedCompleter
        command_action.completer = AndCompleter(ExecutablesCompleter, FilesCompleter())
        input_action.completer = FilesCompleter(dirs=False, file_patterns=["*.rxt"])
        PKG_action.completer = PackageCompleter
        extra_0_action.completer = SequencedCompleter(
            "extra_0", ExecutablesCompleter, FilesCompleter())
Example #12
0
File: system.py Project: rvsiy/rez
    def shell(self):
        """Get the current shell.
        @returns The current shell this process is running in. Examples:

            bash
            tcsh
        """
        from rez.shells import get_shell_types
        shells = set(get_shell_types())
        if not shells:
            raise RezSystemError("no shells available")

        if self.platform == "windows":
            return "cmd"
        else:
            import subprocess as sp
            shell = None

            # check parent process via ps
            try:
                args = ['ps', '-o', 'args=', '-p', str(os.getppid())]
                proc = sp.Popen(args, stdout=sp.PIPE)
                output = proc.communicate()[0]
                shell = os.path.basename(output.strip().split()[0]).replace('-', '')
            except Exception:
                pass

            # check $SHELL
            if shell not in shells:
                shell = os.path.basename(os.getenv("SHELL", ''))

            # traverse parent procs via /proc/(pid)/status
            if shell not in shells:
                pid = str(os.getppid())
                found = False

                while not found:
                    try:
                        file = os.path.join(os.sep, "proc", pid, "status")
                        with open(file) as f:
                            loc = f.read().split('\n')

                        for line in loc:
                            line = line.strip()
                            toks = line.split()
                            if len(toks) == 2:
                                if toks[0] == "Name:":
                                    name = toks[1]
                                    if name in shells:
                                        shell = name
                                        found = True
                                        break
                                elif toks[0] == "PPid:":
                                    pid = toks[1]
                    except Exception:
                        break

            if (shell not in shells) and ("sh" in shells):
                shell = "sh"  # failed detection, fall back on 'sh'
            elif (shell not in shells) and ("bash" in shells):
                shell = "bash"  # failed detection, fall back on 'bash'
            elif shell not in shells:
                shell = iter(shells).next()  # give up - just choose a shell

            # sh has to be handled as a special case
            if shell == "sh":
                if os.path.islink("/bin/sh"):
                    path = os.readlink("/bin/sh")
                    shell2 = os.path.split(path)[-1]

                    if shell2 == "bash":
                        # bash switches to sh-like shell when invoked as sh,
                        # so we want to use the sh shell plugin
                        pass
                    elif shell2 == "dash":
                        # dash doesn't have an sh emulation mode, so we have
                        # to use the dash shell plugin
                        if "dash" in shells:
                            shell = "dash"
                        else:
                            # this isn't good!
                            if "bash" in shells:
                                shell = "bash"  # fall back on bash
                            else:
                                shell = iter(shells).next()  # give up - just choose a shell

            # TODO: remove this when/if dash support added
            if shell == "dash":
                shell = "bash"

            return shell
Example #13
0
File: context.py Project: rvsiy/rez
def setup_parser(parser, completions=False):
    from rez.system import system
    from rez.shells import get_shell_types

    formats = get_shell_types() + ['dict', 'table']
    output_styles = [e.name for e in OutputStyle]

    parser.add_argument(
        "--req", "--print-request", dest="print_request",
        action="store_true",
        help="print only the request list (not including implicits)")
    parser.add_argument(
        "--res", "--print-resolve", dest="print_resolve",
        action="store_true",
        help="print only the resolve list")
    parser.add_argument(
        "--so", "--source-order", dest="source_order", action="store_true",
        help="print resolved packages in order they are sorted, rather than "
        "alphabetical order")
    parser.add_argument(
        "--su", "--show-uris", dest="show_uris", action="store_true",
        help="list resolved package's URIs, rather than the default 'root' "
        "filepath")
    parser.add_argument(
        "-t", "--tools", action="store_true",
        help="print a list of the executables available in the context")
    parser.add_argument(
        "--which", type=str, metavar="CMD",
        help="locate a program within the context")
    parser.add_argument(
        "-g", "--graph", action="store_true",
        help="display the resolve graph as an image")
    parser.add_argument(
        "--pg", "--print-graph", dest="print_graph", action="store_true",
        help="print the resolve graph as a string")
    parser.add_argument(
        "--wg", "--write-graph", dest="write_graph", type=str,
        metavar='FILE', help="write the resolve graph to FILE")
    parser.add_argument(
        "--pp", "--prune-package", dest="prune_pkg", metavar="PKG",
        type=str, help="prune the graph down to PKG")
    parser.add_argument(
        "-i", "--interpret", action="store_true",
        help="interpret the context and print the resulting code")
    parser.add_argument(
        "-f", "--format", type=str, choices=formats, default=system.shell,
        help="print interpreted output in the given format. Ignored if "
        "--interpret is not present (default: "
        "%(default)s)")
    parser.add_argument(
        "-s", "--style", type=str, default="file", choices=output_styles,
        help="Set code output style. Ignored if --interpret is not present "
        "(default: %(default)s)")
    parser.add_argument(
        "--no-env", dest="no_env", action="store_true",
        help="interpret the context in an empty environment")
    diff_action = parser.add_argument(
        "--diff", type=str, metavar="RXT",
        help="diff the current context against the given context")
    parser.add_argument(
        "--fetch", action="store_true",
        help="diff the current context against a re-resolved copy of the "
        "current context")
    RXT_action = parser.add_argument(
        "RXT", type=str, nargs='?',
        help="rez context file (current context if not supplied). Use '-' to "
        "read the context from stdin")

    if completions:
        from rez.cli._complete_util import FilesCompleter
        rxt_completer = FilesCompleter(dirs=False, file_patterns=["*.rxt"])
        RXT_action.completer = rxt_completer
        diff_action.completer = rxt_completer
Example #14
0
def setup_parser(parser, completions=False):
    from rez.vendor.argparse import SUPPRESS
    from rez.config import config
    from rez.system import system
    from rez.shells import get_shell_types

    shells = get_shell_types()

    parser.add_argument(
        "--shell", dest="shell", type=str, choices=shells,
        default=config.default_shell or system.shell,
        help="target shell type (default: %(default)s)")
    parser.add_argument(
        "--rcfile", type=str,
        help="source this file instead of the target shell's standard startup "
        "scripts, if possible")
    parser.add_argument(
        "--norc", action="store_true",
        help="skip loading of startup scripts")
    command_action = parser.add_argument(
        "-c", "--command", type=str,
        help="read commands from string. Alternatively, list command arguments "
        "after a '--'")
    parser.add_argument(
        "-s", "--stdin", action="store_true",
        help="read commands from standard input")
    parser.add_argument(
        "--ni", "--no-implicit", dest="no_implicit",
        action="store_true",
        help="don't add implicit packages to the request")
    parser.add_argument(
        "--nl", "--no-local", dest="no_local", action="store_true",
        help="don't load local packages")
    parser.add_argument(
        "-b", "--build", action="store_true",
        help="create a build environment")
    parser.add_argument(
        "--paths", type=str, default=None,
        help="set package search path")
    parser.add_argument(
        "-t", "--time", type=str,
        help="ignore packages released after the given time. Supported formats "
        "are: epoch time (eg 1393014494), or relative time (eg -10s, -5m, "
        "-0.5h, -10d)")
    parser.add_argument(
        "--max-fails", type=int, default=-1, dest="max_fails",
        metavar='N',
        help="abort if the number of failed configuration attempts exceeds N")
    parser.add_argument(
        "--time-limit", type=int, default=-1,
        dest="time_limit", metavar='SECS',
        help="abort if the resolve time exceeds SECS")
    parser.add_argument(
        "-o", "--output", type=str, metavar="FILE",
        help="store the context into an rxt file, instead of starting an "
        "interactive shell. Note that this will also store a failed resolve. "
        "If you use the special value '-', the context is written to stdout.")
    input_action = parser.add_argument(
        "-i", "--input", type=str, metavar="FILE",
        help="use a previously saved context. Resolve settings, such as PKG, "
        "--ni etc are ignored in this case")
    parser.add_argument(
        "--exclude", type=str, nargs='+', metavar="RULE",
        help="add package exclusion filters, eg '*.beta'. Note that these are "
        "added to the globally configured exclusions")
    parser.add_argument(
        "--include", type=str, nargs='+', metavar="RULE",
        help="add package inclusion filters, eg 'mypkg', 'boost-*'. Note that "
        "these are added to the globally configured inclusions")
    parser.add_argument(
        "--no-filters", dest="no_filters", action="store_true",
        help="turn off package filters. Note that any filters specified with "
        "--exclude/--include are still applied")
    parser.add_argument(
        "-p", "--patch", action="store_true",
        help="patch the current context to create a new context")
    parser.add_argument(
        "--strict", action="store_true",
        help="strict patching. Ignored if --patch is not present")
    parser.add_argument(
        "--patch-rank", type=int, metavar="N", default=0,
        help="patch rank. Ignored if --patch is not present")
    parser.add_argument(
        "--no-cache", dest="no_cache", action="store_true",
        help="do not fetch cached resolves")
    parser.add_argument(
        "-q", "--quiet", action="store_true",
        help="run in quiet mode (hides welcome message)")
    parser.add_argument(
        "--fail-graph", action="store_true",
        help="if the build environment fails to resolve due to a conflict, "
        "display the resolve graph as an image.")
    parser.add_argument(
        "--new-session", action="store_true",
        help="start the shell in a new process group")
    parser.add_argument(
        "--detached", action="store_true",
        help="open a separate terminal")
    parser.add_argument(
        "--no-passive", action="store_true",
        help="only print actions that affect the solve (has an effect only "
        "when verbosity is enabled)")
    parser.add_argument(
        "--stats", action="store_true",
        help="print advanced solver stats")
    parser.add_argument(
        "--pre-command", type=str, help=SUPPRESS)
    PKG_action = parser.add_argument(
        "PKG", type=str, nargs='*',
        help='packages to use in the target environment')
    extra_0_action = parser.add_argument(  # args after --
        "--N0", dest="extra_0", nargs='*',
        help=SUPPRESS)

    if completions:
        from rez.cli._complete_util import PackageCompleter, FilesCompleter, \
            ExecutablesCompleter, AndCompleter, SequencedCompleter
        command_action.completer = AndCompleter(ExecutablesCompleter, FilesCompleter())
        input_action.completer = FilesCompleter(dirs=False, file_patterns=["*.rxt"])
        PKG_action.completer = PackageCompleter
        extra_0_action.completer = SequencedCompleter(
            "extra_0", ExecutablesCompleter, FilesCompleter())
Example #15
0
def parse_wrapped_args(name, args):
    """
    Parse the wrapped arguments in a second pass.

    OPTIONS
    -t --time <timestamp> If not provided, assume we want the latest solve
    -c --context <context> or get from environment
    -d --db rez rxt database
    -t --tool <name> tool
    -l --list list tools
    """
    shells = get_shell_types()

    if args is None:
        return None
    fargs = []

    for arg in args:
        pieces = arg.split(',')
        for piece in pieces:
            no_eq = piece.split('=')
            fargs.append("{0}{1}".format(("--" if len(no_eq[0]) > 1 else "-"),
                                         piece))
    parser = argparse.ArgumentParser(prog="{0} wrapper".format(name),\
             description='Process wrapper arguments and invoke {0}'.format(name))
    parser.add_argument("--ts",
                        "--time",
                        dest="timestamp",
                        help="Time to invoke {0} at".format(argv[0]))
    parser.add_argument("-c",
                        "--context",
                        dest="context",
                        help="Context within which to invoke {0}".format(
                            argv[0]))
    parser.add_argument("-d",
                        "--db",
                        dest="db",
                        help="Path to a database root directory")
    parser.add_argument("-t", "--tool", dest="tool", help="The tool to invoke")
    parser.add_argument("-l",
                        "--list",
                        "--list-tools",
                        dest="list_tools",
                        action="store_true",
                        help="list the tools associated with the resolve.")
    parser.add_argument("-v", "--verbose", action="store_true")
    parser.add_argument("--shell",
                        dest="shell",
                        type=str,
                        choices=shells,
                        default=system.shell,
                        help="target shell type (default: %(default)s)")
    parser.add_argument(
        "--rcfile",
        type=str,
        help="source this file instead of the target shell's standard startup "
        "scripts, if possible")
    parser.add_argument("--norc",
                        action="store_true",
                        help="skip loading of startup scripts")
    parser.add_argument("-s",
                        "--stdin",
                        action="store_true",
                        help="read commands from standard input")
    parser.add_argument("--new-session",
                        action="store_true",
                        help="start the shell in a new process group")
    parser.add_argument("--detached",
                        action="store_true",
                        help="open a separate terminal")
    parser.add_argument("--pre-command", type=str, help=SUPPRESS)

    args = parser.parse_args(fargs)
    return args