示例#1
0
def _FWD__spawn_build_shell(working_dir,
                            build_path,
                            variant_index,
                            install,
                            install_path=None):
    # This spawns a shell that the user can run the build command in directly
    context = ResolvedContext.load(os.path.join(build_path, "build.rxt"))
    package = get_developer_package(working_dir)
    variant = package.get_variant(variant_index)
    config.override("prompt", "BUILD>")

    actions_callback = functools.partial(CustomBuildSystem._add_build_actions,
                                         context=context,
                                         package=package,
                                         variant=variant,
                                         build_type=BuildType.local,
                                         install=install,
                                         build_path=build_path,
                                         install_path=install_path)

    post_actions_callback = functools.partial(
        CustomBuildSystem.add_pre_build_commands,
        variant=variant,
        build_type=BuildType.local,
        install=install,
        build_path=build_path,
        install_path=install_path)

    retcode, _, _ = context.execute_shell(
        block=True,
        cwd=build_path,
        actions_callback=actions_callback,
        post_actions_callback=post_actions_callback)

    sys.exit(retcode)
示例#2
0
def _FWD__spawn_build_shell(working_dir, build_dir):
    # This spawns a shell that the user can run 'bez' in directly
    context = ResolvedContext.load(os.path.join(build_dir, "build.rxt"))
    config.override("prompt", "BUILD>")

    retcode, _, _ = context.execute_shell(block=True, cwd=build_dir)
    sys.exit(retcode)
示例#3
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)
示例#4
0
    def test_8(self):
        """Custom environment variable separators."""

        config.override("env_var_separators", {"FOO": ",", "BAH": " "})

        def _rex():
            appendenv("FOO", "test1")
            env.FOO.append("test2")
            env.FOO.append("test3")

            env.BAH.prepend("A")
            prependenv("BAH", "B")
            env.BAH.append("C")

        self._test(func=_rex,
                   env={},
                   expected_actions=[
                       Setenv('FOO', 'test1'),
                       Appendenv('FOO', 'test2'),
                       Appendenv('FOO', 'test3'),
                       Setenv('BAH', 'A'),
                       Prependenv('BAH', 'B'),
                       Appendenv('BAH', 'C')
                   ],
                   expected_output={
                       'FOO': ",".join(["test1", "test2", "test3"]),
                       'BAH': " ".join(["B", "A", "C"])
                   })
示例#5
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
示例#6
0
文件: test_rex.py 项目: rvsiy/rez
    def test_8(self):
        """Custom environment variable separators."""

        config.override("env_var_separators", {"FOO":",", "BAH":" "})

        def _rex():
            appendenv("FOO", "test1")
            env.FOO.append("test2")
            env.FOO.append("test3")

            env.BAH.prepend("A")
            prependenv("BAH", "B")
            env.BAH.append("C")

        self._test(func=_rex,
                   env={},
                   expected_actions = [
                       Setenv('FOO', 'test1'),
                       Appendenv('FOO', 'test2'),
                       Appendenv('FOO', 'test3'),
                       Setenv('BAH', 'A'),
                       Prependenv('BAH', 'B'),
                       Appendenv('BAH', 'C')],
                   expected_output = {
                       'FOO': ",".join(["test1","test2","test3"]),
                       'BAH': " ".join(["B","A","C"])})
示例#7
0
文件: forward.py 项目: wwfxuk/rez
def command(opts, parser, extra_arg_groups=None):
    from rez.config import config
    from rez.utils.platform_ import platform_
    from rez.exceptions import RezSystemError
    from rez.vendor import yaml
    from rez.vendor.yaml.error import YAMLError
    from rez.utils import py23
    import os.path

    # we don't usually want warnings printed in a wrapped tool. But in cases
    # where we do (for debugging) we leave a backdoor - setting $REZ_QUIET=0
    # will stop this warning suppression.
    if "REZ_QUIET" not in os.environ:
        config.override("quiet", True)

    yaml_file = os.path.abspath(opts.YAML)

    cli_args = opts.ARG
    for arg_group in (extra_arg_groups or []):
        cli_args.extend(arg_group)

    if platform_.name == "windows" and yaml_file.lower().endswith(".cmd"):
        with open(yaml_file) as f:
            content = "\n".join(f.readlines()[4:])  # strip batch script
    else:
        with open(yaml_file) as f:
            content = f.read()

    try:
        doc = yaml.load(content, Loader=yaml.FullLoader)
    except YAMLError as e:
        raise RezSystemError("Invalid executable file %s: %s" %
                             (yaml_file, str(e)))

    func_name = doc["func_name"]
    nargs = doc.get("nargs", [])
    kwargs = doc.get("kwargs", {})

    if isinstance(doc["module"], basestring):
        # refers to a rez module
        from rez.backport.importlib import import_module
        namespace = "rez.%s" % doc["module"]
        module = import_module(namespace)
    else:
        # refers to a rez plugin module
        from rez.plugin_managers import plugin_manager
        plugin_type, plugin_name = doc["module"]
        module = plugin_manager.get_plugin_module(plugin_type, plugin_name)

    target_func = getattr(module, func_name)
    func_args = py23.get_function_arg_names(target_func)

    if "_script" in func_args:
        kwargs["_script"] = yaml_file
    if "_cli_args" in func_args:
        kwargs["_cli_args"] = cli_args

    target_func(*nargs, **kwargs)
示例#8
0
    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
示例#9
0
    def test_singleton_novalue(self):
        """Validate we can build a PackageOrderList object from empty configuration values."""
        config.override("package_orderers", None)

        # Clear @classproperty cache
        try:
            delattr(PackageOrderList, '_class_property_singleton')
        except AttributeError:
            pass

        self.assertEqual(PackageOrderList(), PackageOrderList.singleton)
示例#10
0
    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
示例#11
0
def command(opts, parser, extra_arg_groups=None):
    from rez.package_search import ResourceSearcher, ResourceSearchResultFormatter
    from rez.utils.formatting import get_epoch_time_from_str
    from rez.config import config

    before_time = get_epoch_time_from_str(opts.before)
    after_time = get_epoch_time_from_str(opts.after)

    if after_time and before_time and (after_time >= before_time):
        parser.error("non-overlapping --before and --after")

    if opts.no_warnings:
        config.override("warn_none", True)

    if opts.paths:
        paths = opts.paths.split(os.pathsep)
        paths = [x for x in paths if x]
    else:
        paths = None

    if opts.type == "auto":
        type_ = None
    else:
        type_ = opts.type

    searcher = ResourceSearcher(
        package_paths=paths,
        resource_type=type_,
        no_local=opts.no_local,
        latest=opts.latest,
        after_time=after_time,
        before_time=before_time,
        validate=(opts.validate or opts.errors)
    )

    resource_type, search_results = searcher.search(opts.PKG)

    if opts.errors:
        search_results = [x for x in search_results if x.validation_error]

        if not search_results:
            print >> sys.stderr, "No matching erroneous %s found." % resource_type
            sys.exit(1)

    elif not search_results:
        print >> sys.stderr, "No matching %s found." % resource_type
        sys.exit(1)

    formatter = ResourceSearchResultFormatter(
        output_format=opts.format,
        suppress_newlines=opts.no_newlines
    )

    formatter.print_search_results(search_results)
示例#12
0
文件: util.py 项目: 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)
示例#13
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)
示例#14
0
文件: forward.py 项目: rvsiy/rez
def command(opts, parser, extra_arg_groups=None):
    from rez.config import config
    from rez.exceptions import RezSystemError
    from rez.vendor import yaml
    from rez.vendor.yaml.error import YAMLError
    import inspect
    import os.path

    # we don't usually want warnings printed in a wrapped tool. But in cases
    # where we do (for debugging) we leave a backdoor - setting $REZ_QUIET=0
    # will stop this warning suppression.
    if "REZ_QUIET" not in os.environ:
        config.override("quiet", True)

    yaml_file = os.path.abspath(opts.YAML)

    cli_args = opts.ARG
    for arg_group in (extra_arg_groups or []):
        cli_args.append("--")
        cli_args.extend(arg_group)

    with open(yaml_file) as f:
        content = f.read()
    try:
        doc = yaml.load(content)
    except YAMLError as e:
        raise RezSystemError("Invalid executable file %s: %s"
                             % (yaml_file, str(e)))

    func_name = doc["func_name"]
    nargs = doc.get("nargs", [])
    kwargs = doc.get("kwargs", {})

    if isinstance(doc["module"], basestring):
        # refers to a rez module
        from rez.backport.importlib import import_module
        namespace = "rez.%s" % doc["module"]
        module = import_module(namespace)
    else:
        # refers to a rez plugin module
        from rez.plugin_managers import plugin_manager
        plugin_type, plugin_name = doc["module"]
        module = plugin_manager.get_plugin_module(plugin_type, plugin_name)

    target_func = getattr(module, func_name)
    func_args = inspect.getargspec(target_func).args
    if "_script" in func_args:
        kwargs["_script"] = yaml_file
    if "_cli_args" in func_args:
        kwargs["_cli_args"] = cli_args

    target_func(*nargs, **kwargs)
示例#15
0
文件: search.py 项目: opcg/rez
def command(opts, parser, extra_arg_groups=None):
    from rez.package_search import ResourceSearcher, ResourceSearchResultFormatter
    from rez.utils.formatting import get_epoch_time_from_str
    from rez.config import config

    before_time = get_epoch_time_from_str(opts.before)
    after_time = get_epoch_time_from_str(opts.after)

    if after_time and before_time and (after_time >= before_time):
        parser.error("non-overlapping --before and --after")

    if opts.no_warnings:
        config.override("warn_none", True)

    if opts.paths:
        paths = opts.paths.split(os.pathsep)
        paths = [x for x in paths if x]
    else:
        paths = None

    if opts.type == "auto":
        type_ = None
    else:
        type_ = opts.type

    searcher = ResourceSearcher(package_paths=paths,
                                resource_type=type_,
                                no_local=opts.no_local,
                                latest=opts.latest,
                                after_time=after_time,
                                before_time=before_time,
                                validate=(opts.validate or opts.errors))

    resource_type, search_results = searcher.search(opts.PKG)

    if opts.errors:
        search_results = [x for x in search_results if x.validation_error]

        if not search_results:
            print("No matching erroneous %s found." % resource_type,
                  file=sys.stderr)
            sys.exit(1)

    elif not search_results:
        print("No matching %s found." % resource_type, file=sys.stderr)
        sys.exit(1)

    formatter = ResourceSearchResultFormatter(
        output_format=opts.format, suppress_newlines=opts.no_newlines)

    formatter.print_search_results(search_results)
示例#16
0
文件: cmake.py 项目: cb109/rez
def _FWD__spawn_build_shell(working_dir, build_dir, variant_index):
    # This spawns a shell that the user can run 'make' in directly
    context = ResolvedContext.load(os.path.join(build_dir, "build.rxt"))
    package = get_developer_package(working_dir)
    variant = package.get_variant(variant_index)
    config.override("prompt", "BUILD>")

    callback = functools.partial(CMakeBuildSystem._add_build_actions,
                                 context=context,
                                 package=package,
                                 variant=variant,
                                 build_type=BuildType.local)

    retcode, _, _ = context.execute_shell(block=True,
                                          cwd=build_dir,
                                          actions_callback=callback)
    sys.exit(retcode)
示例#17
0
文件: cmake.py 项目: mwiebe/rez
def _FWD__spawn_build_shell(working_dir, build_dir, variant_index):
    # This spawns a shell that the user can run 'make' in directly
    context = ResolvedContext.load(os.path.join(build_dir, "build.rxt"))
    package = get_developer_package(working_dir)
    variant = package.get_variant(variant_index)
    config.override("prompt", "BUILD>")

    callback = functools.partial(CMakeBuildSystem._add_build_actions,
                                 context=context,
                                 package=package,
                                 variant=variant,
                                 build_type=BuildType.local)

    retcode, _, _ = context.execute_shell(block=True,
                                          cwd=build_dir,
                                          actions_callback=callback)
    sys.exit(retcode)
示例#18
0
def command(opts, parser, extra_arg_groups=None):
    from rez.package_search import get_plugins
    from rez.config import config
    import os
    import os.path
    import sys

    config.override("warn_none", True)

    if opts.paths is None:
        pkg_paths = None
    else:
        pkg_paths = opts.paths.split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    pkgs_list = get_plugins(package_name=opts.PKG, paths=pkg_paths)
    if pkgs_list:
        print '\n'.join(pkgs_list)
    else:
        print >> sys.stderr, "package '%s' has no plugins." % opts.PKG
示例#19
0
def command(opts, parser, extra_arg_groups=None):
    from rez.package_search import get_reverse_dependency_tree
    from rez.utils.graph_utils import save_graph, view_graph
    from rez.config import config
    from rez.vendor.pygraph.readwrite.dot import write as write_dot
    import os
    import os.path

    config.override("warn_none", True)
    config.override("show_progress", (not opts.quiet))

    if opts.paths is None:
        pkg_paths = None
    else:
        pkg_paths = opts.paths.split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    pkgs_list, g = get_reverse_dependency_tree(
        package_name=opts.PKG,
        depth=opts.depth,
        paths=pkg_paths,
        build_requires=opts.build_requires,
        private_build_requires=opts.private_build_requires)

    if opts.graph or opts.print_graph or opts.write_graph:
        gstr = write_dot(g)
        if opts.print_graph:
            print(gstr)
        elif opts.write_graph:
            save_graph(gstr, dest_file=opts.write_graph)
        else:
            view_graph(gstr)
        return 0

    for i, pkgs in enumerate(pkgs_list):
        if opts.quiet:
            toks = pkgs
        else:
            toks = ["#%d:" % i] + pkgs
        print(' '.join(toks))
示例#20
0
def command(opts, parser, extra_arg_groups=None):
    from rez.package_search import get_reverse_dependency_tree
    from rez.utils.graph_utils import save_graph, view_graph
    from rez.config import config
    from rez.vendor.pygraph.readwrite.dot import write as write_dot
    import os
    import os.path

    config.override("warn_none", True)
    config.override("show_progress", (not opts.quiet))

    if opts.paths is None:
        pkg_paths = None
    else:
        pkg_paths = opts.paths.split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    pkgs_list, g = get_reverse_dependency_tree(
        package_name=opts.PKG,
        depth=opts.depth,
        paths=pkg_paths,
        build_requires=opts.build_requires,
        private_build_requires=opts.private_build_requires)

    if opts.graph or opts.print_graph or opts.write_graph:
        gstr = write_dot(g)
        if opts.print_graph:
            print gstr
        elif opts.write_graph:
            save_graph(gstr, dest_file=opts.write_graph)
        else:
            view_graph(gstr)
        return 0

    for i, pkgs in enumerate(pkgs_list):
        if opts.quiet:
            toks = pkgs
        else:
            toks = ["#%d:" % i] + pkgs
        print ' '.join(toks)
示例#21
0
def _FWD__invoke_suite_tool_alias_in_live(package_requests,
                                          context_name,
                                          tool_name,
                                          prefix_char=None,
                                          _script=None,
                                          _cli_args=None):
    # Load configs
    from rez.resolved_context import ResolvedContext
    from rez.config import _load_config_from_filepaths, config
    configs = find_configs(os.getcwd())
    overrides, _ = _load_config_from_filepaths(configs)
    for key, value in overrides.items():
        config.override(key, value)

    suite_path = os.path.dirname(os.path.dirname(_script))
    context = ResolvedContext(package_requests)

    from rez.wrapper import Wrapper
    w = Wrapper.__new__(Wrapper)
    w._init(suite_path, context_name, context, tool_name, prefix_char)
    retcode = w.run(*(_cli_args or []))
    sys.exit(retcode)
示例#22
0
    def test_singleton(self):
        """Validate we can build a PackageOrderList object from configuration values."""
        config.override("package_orderers", [{
            "type":
            "per_family",
            "orderers": [{
                "packages": ["python"],
                "type": "version_split",
                "first_version": "2.9.9"
            }]
        }])
        expected = PackageOrderList()
        expected.append(
            PerFamilyOrder(order_dict={
                "python": VersionSplitPackageOrder(Version("2.9.9"))
            }))

        # Clear @classproperty cache
        try:
            delattr(PackageOrderList, '_class_property_singleton')
        except AttributeError:
            pass
        self.assertEqual(expected, PackageOrderList.singleton)
示例#23
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
示例#24
0
def command(opts, parser, extra_arg_groups=None):
    from rez.config import config
    from rez.exceptions import RezError
    from rez.utils.formatting import get_epoch_time_from_str, expand_abbreviations
    from rez.utils.logging_ import print_error
    from rez.packages_ import iter_package_families, iter_packages
    from rez.vendor.version.requirement import Requirement
    import os.path
    import fnmatch
    import sys

    error_class = None if opts.debug else RezError

    before_time = 0
    after_time = 0
    if opts.before:
        before_time = get_epoch_time_from_str(opts.before)
    if opts.after:
        after_time = get_epoch_time_from_str(opts.after)
    if after_time and before_time and (after_time >= before_time):
        parser.error("non-overlapping --before and --after")

    if opts.paths is None:
        pkg_paths = config.nonlocal_packages_path if opts.no_local else None
    else:
        pkg_paths = (opts.paths or "").split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    name_pattern = opts.PKG or '*'
    version_range = None
    if opts.PKG:
        try:
            req = Requirement(opts.PKG)
            name_pattern = req.name
            if not req.range.is_any():
                version_range = req.range
        except:
            pass

    type_ = opts.type
    if opts.errors or (type_ == "auto" and version_range):
        type_ = "package"
        # turn some of the nastier rez-1 warnings into errors
        config.override("error_package_name_mismatch", True)
        config.override("error_version_mismatch", True)
        config.override("error_nonstring_version", True)

    if opts.no_warnings:
        config.override("warn_none", True)

    # families
    found = False
    family_names = []
    families = iter_package_families(paths=pkg_paths)
    if opts.sort:
        families = sorted(families, key=lambda x: x.name)
    for family in families:
        if family.name not in family_names and \
                fnmatch.fnmatch(family.name, name_pattern):
            family_names.append(family.name)
            if type_ == "auto":
                type_ = "package" if family.name == name_pattern else "family"
            if type_ == "family":
                print family.name
                found = True

    def _handle(e):
        print_error(str(e))

    def _print_resource(r):
        if opts.validate:
            try:
                r.validate_data()
            except error_class as e:
                _handle(e)
                return

        if opts.format:
            txt = expand_abbreviations(opts.format, fields)
            lines = txt.split("\\n")
            for line in lines:
                try:
                    line_ = r.format(line)
                except error_class as e:
                    _handle(e)
                    break
                if opts.no_newlines:
                    line_ = line_.replace('\n', "\\n")

                print line_
        else:
            print r.qualified_name

    # packages/variants
    if type_ in ("package", "variant"):
        for name in family_names:
            packages = iter_packages(name, version_range, paths=pkg_paths)
            if opts.sort or opts.latest:
                packages = sorted(packages, key=lambda x: x.version)
                if opts.latest and packages:
                    packages = [packages[-1]]

            for package in packages:
                if ((before_time or after_time) and package.timestamp and
                    (before_time and package.timestamp >= before_time
                     or after_time and package.timestamp <= after_time)):
                    continue

                if opts.errors:
                    try:
                        package.validate_data()
                    except error_class as e:
                        _handle(e)
                        found = True
                elif type_ == "package":
                    _print_resource(package)
                    found = True
                elif type_ == "variant":
                    try:
                        package.validate_data()
                    except error_class as e:
                        _handle(e)
                        continue

                    try:
                        for variant in package.iter_variants():
                            _print_resource(variant)
                            found = True
                    except error_class as e:
                        _handle(e)
                        continue

    if not found:
        if opts.errors:
            print "no erroneous packages found"
        else:
            print "no matches found"
            sys.exit(1)
示例#25
0
文件: wrapper.py 项目: rvsiy/rez
    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
示例#26
0
 def test_10_intersection_priority_mode(self):
     config.override("variant_select_mode", "intersection_priority")
     self._solve(["pyvariants", "python"],
                 ["python-2.7.0[]", "pyvariants-2[0]"])
     self._solve(["pyvariants", "python", "nada"],
                 ["python-2.6.8[]", "nada[]", "pyvariants-2[1]"])
示例#27
0
 def test_09_version_priority_mode(self):
     config.override("variant_select_mode", "version_priority")
     self._solve(["pyvariants", "python"],
                 ["python-2.7.0[]", "pyvariants-2[0]"])
     self._solve(["pyvariants", "python", "nada"],
                 ["python-2.7.0[]", "pyvariants-2[0]", "nada[]"])
示例#28
0
def command(opts, parser, extra_arg_groups=None):
    from rez.config import config
    from rez.exceptions import RezError
    from rez.utils.formatting import get_epoch_time_from_str, expand_abbreviations
    from rez.utils.logging_ import print_error
    from rez.packages_ import iter_package_families, iter_packages
    from rez.vendor.version.requirement import Requirement
    import os.path
    import fnmatch
    import sys

    error_class = None if opts.debug else RezError

    before_time = 0
    after_time = 0
    if opts.before:
        before_time = get_epoch_time_from_str(opts.before)
    if opts.after:
        after_time = get_epoch_time_from_str(opts.after)
    if after_time and before_time and (after_time >= before_time):
        parser.error("non-overlapping --before and --after")

    if opts.paths is None:
        pkg_paths = config.nonlocal_packages_path if opts.no_local else None
    else:
        pkg_paths = (opts.paths or "").split(os.pathsep)
        pkg_paths = [os.path.expanduser(x) for x in pkg_paths if x]

    name_pattern = opts.PKG or '*'
    version_range = None
    if opts.PKG:
        try:
            req = Requirement(opts.PKG)
            name_pattern = req.name
            if not req.range.is_any():
                version_range = req.range
        except:
            pass

    type_ = opts.type
    if opts.errors or (type_ == "auto" and version_range):
        type_ = "package"
        # turn some of the nastier rez-1 warnings into errors
        config.override("error_package_name_mismatch", True)
        config.override("error_version_mismatch", True)
        config.override("error_nonstring_version", True)

    if opts.no_warnings:
        config.override("warn_none", True)

    # families
    found = False
    family_names = []
    families = iter_package_families(paths=pkg_paths)
    if opts.sort:
        families = sorted(families, key=lambda x: x.name)
    for family in families:
        if family.name not in family_names and \
                fnmatch.fnmatch(family.name, name_pattern):
            family_names.append(family.name)
            if type_ == "auto":
                type_ = "package" if family.name == name_pattern else "family"
            if type_ == "family":
                print family.name
                found = True

    def _handle(e):
        print_error(str(e))

    def _print_resource(r):
        if opts.validate:
            try:
                r.validate_data()
            except error_class as e:
                _handle(e)
                return

        if opts.format:
            txt = expand_abbreviations(opts.format, fields)
            lines = txt.split("\\n")
            for line in lines:
                try:
                    line_ = r.format(line)
                except error_class as e:
                    _handle(e)
                    break
                if opts.no_newlines:
                    line_ = line_.replace('\n', "\\n")

                print line_
        else:
            print r.qualified_name

    # packages/variants
    if type_ in ("package", "variant"):
        for name in family_names:
            packages = iter_packages(name, version_range, paths=pkg_paths)
            if opts.sort or opts.latest:
                packages = sorted(packages, key=lambda x: x.version)
                if opts.latest and packages:
                    packages = [packages[-1]]

            for package in packages:
                if ((before_time or after_time)
                    and package.timestamp
                    and (before_time and package.timestamp >= before_time
                         or after_time and package.timestamp <= after_time)):
                    continue

                if opts.errors:
                    try:
                        package.validate_data()
                    except error_class as e:
                        _handle(e)
                        found = True
                elif type_ == "package":
                    _print_resource(package)
                    found = True
                elif type_ == "variant":
                    try:
                        package.validate_data()
                    except error_class as e:
                        _handle(e)
                        continue

                    try:
                        for variant in package.iter_variants():
                            _print_resource(variant)
                            found = True
                    except error_class as e:
                        _handle(e)
                        continue

    if not found:
        if opts.errors:
            print "no erroneous packages found"
        else:
            print "no matches found"
            sys.exit(1)