How to use the rez.exceptions.ResourceError function in rez

To help you get started, we’ve selected a few rez examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nerdvegas / rez / src / rezplugins / package_repository / filesystem.py View on Github external
if len(uuids) > 1 and None not in uuids:
                    raise ResourceError(
                        "Cannot install variant %r into package %r - the "
                        "packages are not the same (UUID mismatch)"
                        % (variant, package))

                existing_package = package

                if variant.index is None:
                    if package.variants:
                        raise ResourceError(
                            "Attempting to install a package without variants "
                            "(%r) into an existing package with variants (%r)"
                            % (variant, package))
                elif not package.variants:
                    raise ResourceError(
                        "Attempting to install a variant (%r) into an existing "
                        "package without variants (%r)" % (variant, package))

        existing_package_data = None
        release_data = {}

        # Need to treat 'config' as special case. In validated data, this is
        # converted to a Config object. We need it as the raw dict that you'd
        # see in a package.py.
        #
        def _get_package_data(pkg):
            data = pkg.validated_data()
            if hasattr(pkg, "_data"):
                raw_data = pkg._data
            else:
                raw_data = pkg.resource._data
github nerdvegas / rez / src / rez / resources.py View on Github external
Args:
            path (str): Path or filepath representing the resource.
            search_paths (list of str): Search path(s) that was used to create
                the resource. This is used to decode the path to extract
                variables such as package name and version.

        Returns:
            `Resource` instance.
        """
        if cls.sub_resource:
            raise ResourceError("A sub-resource cannot be loaded from only "
                                "a path")

        filepath = os.path.abspath(path)
        if not cls.path_pattern:
            raise ResourceError("Cannot create resource %r from %r: "
                                "does not have path patterns" %
                                (cls.key, filepath))

        search_paths = search_paths or cls._default_search_paths(path)
        result = _ResourcePathParser.parse_filepath(cls, filepath,
                                                    search_paths)
        if result is None:
            raise ResourceError("Cannot create resource %r from %r: "
                                "file did not match path patterns" %
                                (cls.key, filepath))
        variables = result[1]
        return cls(filepath, variables)
github nerdvegas / rez / src / rez / resources.py View on Github external
clss = list_resource_classes(keys)
        return root_class, [c for c in clss if c.topmost() == root_class]
    else:
        resource_classes = set()
        clss = list_resource_classes(keys)
        if not clss:
            msg = "no such resource type(s) %s" % ", ".join(keys)
            if root_key:
                msg += " in resource hierarchy %s" % root_key
            raise ResourceError(msg)

        # all root classes must match
        root_class = clss[0].topmost()
        for cls in clss:
            if root_class != cls.topmost():
                raise ResourceError(
                    "Resources from different "
                    "hierarchies were requested: %s, %s"
                    % (list(resource_classes)[-1].key, cls.key))
            resource_classes.add(cls)
        return root_class, list(resource_classes)
github nerdvegas / rez / src / rez / resources.py View on Github external
raise ResourceError("Specified multiple resource roots: %s"
                                % root_key)
        elif not clss:
            raise ResourceError("Unknown root resource type %s" % root_key)
        root_class = clss[0]
        # if keys is none, will return all resource classes
        clss = list_resource_classes(keys)
        return root_class, [c for c in clss if c.topmost() == root_class]
    else:
        resource_classes = set()
        clss = list_resource_classes(keys)
        if not clss:
            msg = "no such resource type(s) %s" % ", ".join(keys)
            if root_key:
                msg += " in resource hierarchy %s" % root_key
            raise ResourceError(msg)

        # all root classes must match
        root_class = clss[0].topmost()
        for cls in clss:
            if root_class != cls.topmost():
                raise ResourceError(
                    "Resources from different "
                    "hierarchies were requested: %s, %s"
                    % (list(resource_classes)[-1].key, cls.key))
            resource_classes.add(cls)
        return root_class, list(resource_classes)
github nerdvegas / rez / src / rez / resources.py View on Github external
"""
    if root_key is None and not keys:
        raise ResourceError("Most provide root key or resource key(s)")

    if isinstance(keys, basestring):
        keys = (keys,)
    elif isinstance(keys, list):
        keys = tuple(keys)

    if root_key:
        clss = list_resource_classes(root_key)
        if len(clss) > 1:
            raise ResourceError("Specified multiple resource roots: %s"
                                % root_key)
        elif not clss:
            raise ResourceError("Unknown root resource type %s" % root_key)
        root_class = clss[0]
        # if keys is none, will return all resource classes
        clss = list_resource_classes(keys)
        return root_class, [c for c in clss if c.topmost() == root_class]
    else:
        resource_classes = set()
        clss = list_resource_classes(keys)
        if not clss:
            msg = "no such resource type(s) %s" % ", ".join(keys)
            if root_key:
                msg += " in resource hierarchy %s" % root_key
            raise ResourceError(msg)

        # all root classes must match
        root_class = clss[0].topmost()
        for cls in clss:
github nerdvegas / rez / src / rez / resources.py View on Github external
    @classmethod
    def _default_search_paths(cls, path=None):
        if path:
            return [os.path.dirname(os.path.abspath(path))]
        else:
            raise ResourceError("This type of resources requires explicit "
                                "search path(s)")
github nerdvegas / rez / src / rez / package_repository.py View on Github external
def get_resource_from_handle(self, resource_handle, verify_repo=True):
        """Get a resource.

        Args:
            resource_handle (`ResourceHandle`): Handle of the resource.

        Returns:
            `PackageRepositoryResource` instance.
        """
        if verify_repo:
            # we could fix the handle at this point, but handles should
            # always be made from repo.make_resource_handle... for now,
            # at least, error to catch any "incorrect" construction of
            # handles...
            if resource_handle.variables.get("repository_type") != self.name():
                raise ResourceError("repository_type mismatch - requested %r, "
                                    "repository_type is %r"
                                    % (resource_handle.variables["repository_type"],
                                       self.name()))

            if resource_handle.variables.get("location") != self.location:
                raise ResourceError("location mismatch - requested %r, "
                                    "repository location is %r "
                                    % (resource_handle.variables["location"],
                                       self.location))

        resource = self.pool.get_resource_from_handle(resource_handle)
        resource._repository = self
        return resource
github nerdvegas / rez / src / rez / serialise.py View on Github external
import types
                fn = types.FunctionType(func.__code__,
                                        func.__globals__.copy(),
                                        name=func.__name__,
                                        argdefs=func.__defaults__,
                                        closure=func.__closure__)

                # apply globals
                fn.__globals__["this"] = EarlyThis(data)
                fn.__globals__.update(get_objects())

                # execute the function
                args = py23.get_function_arg_names(func)

                if len(args) not in (0, 1):
                    raise ResourceError("@early decorated function must "
                                        "take zero or one args only")
                if args:
                    # this 'data' arg support isn't needed anymore, but I'm
                    # supporting it til I know nobody is using it...
                    #
                    value_ = fn(data)
                else:
                    value_ = fn()

                # process again in case this is a function returning a function
                return _process(value_)

            elif hasattr(func, "_late"):
                return SourceCode(func=func, filepath=filepath,
                                  eval_as_function=True)
github nerdvegas / rez / src / rez / resources.py View on Github external
Returns:
        `Resource` class: Root resource type.
        list of `Resource` classes: Matching subclass types.
    """
    if root_key is None and not keys:
        raise ResourceError("Most provide root key or resource key(s)")

    if isinstance(keys, basestring):
        keys = (keys,)
    elif isinstance(keys, list):
        keys = tuple(keys)

    if root_key:
        clss = list_resource_classes(root_key)
        if len(clss) > 1:
            raise ResourceError("Specified multiple resource roots: %s"
                                % root_key)
        elif not clss:
            raise ResourceError("Unknown root resource type %s" % root_key)
        root_class = clss[0]
        # if keys is none, will return all resource classes
        clss = list_resource_classes(keys)
        return root_class, [c for c in clss if c.topmost() == root_class]
    else:
        resource_classes = set()
        clss = list_resource_classes(keys)
        if not clss:
            msg = "no such resource type(s) %s" % ", ".join(keys)
            if root_key:
                msg += " in resource hierarchy %s" % root_key
            raise ResourceError(msg)
github nerdvegas / rez / src / rez / utils / resources.py View on Github external
def get_resource_class(self, resource_key):
        resource_class = self.resource_classes.get(resource_key)
        if resource_class is None:
            raise ResourceError("Error getting resource from pool: Unknown "
                                "resource type %r" % resource_key)
        return resource_class