How to use the rez.vendor.schema.schema.Schema 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 / rez / package_resources.py View on Github external
# ------------------------------------------------------------------------------
# utility schemas
# ------------------------------------------------------------------------------

help_schema = Or(basestring,  # single help entry
                 [[basestring]])  # multiple help entries

_is_late = And(SourceCode, lambda x: hasattr(x, "_late"))

def late_bound(schema):
    return Or(SourceCode, schema)

# used when 'requires' is late bound
late_requires_schema = Schema([
    Or(PackageRequest, And(basestring, Use(PackageRequest)))
])


# ------------------------------------------------------------------------------
# schema dicts
# ------------------------------------------------------------------------------

# requirements of all package-related resources
#

base_resource_schema_dict = {
    Required("name"):                   basestring
}
github nerdvegas / rez / src / rez / package_resources.py View on Github external
Optional("variants"):               [[PackageRequest]]
})


# variant
variant_schema_dict = package_base_schema_dict.copy()


# ------------------------------------------------------------------------------
# resource schemas
# ------------------------------------------------------------------------------

package_family_schema = Schema(package_family_schema_dict)


package_schema = Schema(package_schema_dict)


variant_schema = Schema(variant_schema_dict)


# ------------------------------------------------------------------------------
# schemas for converting from POD datatypes
# ------------------------------------------------------------------------------

_commands_schema = Or(SourceCode,       # commands as converted function
                      callable,         # commands as function
                      basestring,       # commands in text block
                      [basestring])     # old-style (rez-1) commands

_function_schema = Or(SourceCode, callable)
github nerdvegas / rez / src / rez / settings.py View on Github external
from rez.vendor.schema.schema import Schema, SchemaError, Or



class PartialFormatter(string.Formatter):
    def get_field(self, key, args, kwargs):
        try:
            return super(PartialFormatter, self).get_field(key, args, kwargs)
        except (KeyError, AttributeError):
            return "{%s}" % key, key


class Settings(object):
    bool_schema         = Schema(bool, error="Expected boolean")
    str_schema          = Schema(str, error="Expected string")
    opt_str_schema      = Schema(Or(str,None), error="Expected string or null")
    int_schema          = Schema(int, error="Expected integer")
    str_list_schema     = Schema([str], error="Expected list of strings")
    path_list_schema    = Schema([str], error="Expected list of strings")

    key_schemas = {
        # bools
        "add_bootstrap_path":               bool_schema,
        "prefix_prompt":                    bool_schema,
        "warn_shell_startup":               bool_schema,
        "warn_untimestamped":               bool_schema,
        "warn_old_commands":                bool_schema,
        "warn_all":                         bool_schema,
        "debug_plugins":                    bool_schema,
        "debug_package_release":            bool_schema,
        "debug_system":                     bool_schema,
        "debug_bind_modules":               bool_schema,
github nerdvegas / rez / src / rez / config.py View on Github external
return Or(
            And(int, lambda x: x > 0),
            And("physical_cores", Use(lambda x: platform_.physical_cores)),
            And("logical_cores", Use(lambda x: platform_.logical_cores)),
        )

    def _parse_env_var(self, value):
        try:
            return int(value)
        except ValueError:
            # wasn't a string - hopefully it's "physical" or "logical"...
            # ...but this will be validated by the schema...
            return value


config_schema = Schema({
    "packages_path":                                PathList,
    "plugin_path":                                  PathList,
    "bind_module_path":                             PathList,
    "standard_system_paths":                        PathList,
    "package_definition_build_python_paths":        PathList,
    "implicit_packages":                            StrList,
    "platform_map":                                 OptionalDict,
    "parent_variables":                             StrList,
    "resetting_variables":                          StrList,
    "release_hooks":                                StrList,
    "context_tracking_context_fields":              StrList,
    "prompt_release_message":                       Bool,
    "critical_styles":                              OptionalStrList,
    "error_styles":                                 OptionalStrList,
    "warning_styles":                               OptionalStrList,
    "info_styles":                                  OptionalStrList,
github nerdvegas / rez / to_delete / config_resources.py View on Github external
# -----------------------------------------------------------------------------

class Setting(object):
    schema = Schema(object)


class Str(Setting):
    schema = Schema(basestring)


class OptionalStr(Setting):
    schema = Or(None, basestring)


class StrList(Setting):
    schema = Schema([basestring])


class PathList(StrList):
    pass


class Int(Setting):
    schema = Schema(int)


class Bool(Setting):
    schema = Schema(bool)


_config_dict = {
    "packages_path":                PathList,
github nerdvegas / rez / to_delete / config_resources.py View on Github external
def _to(value):
        if isinstance(value, dict):
            d = {}
            for k, v in value.iteritems():
                if isinstance(k, basestring):
                    k_ = Required(k) if required else Optional(k)
                else:
                    k_ = k
                d[k_] = _to(v)
            if allow_custom_keys:
                d[Optional(basestring)] = (Expand()
                                           if inject_expansion else object)
            schema = Schema(d)
        else:
            if type(value) is type and issubclass(value, Setting):
                schema = value.schema
            else:
                schema = value
            if inject_expansion:
                schema = And(schema, Expand())
        return schema
github nerdvegas / rez / src / rez / config.py View on Github external
def _validate_key(self, key, value, key_schema):
        if type(key_schema) is type and issubclass(key_schema, Setting):
            key_schema = key_schema(self, key)
        elif not isinstance(key_schema, Schema):
            key_schema = Schema(key_schema)
        return key_schema.validate(value)
github nerdvegas / rez / src / rez / package_resources.py View on Github external
package_schema_dict = package_base_schema_dict.copy()
package_schema_dict.update({
    # deliberately not possible to late bind
    Optional("variants"):               [[PackageRequest]]
})


# variant
variant_schema_dict = package_base_schema_dict.copy()


# ------------------------------------------------------------------------------
# resource schemas
# ------------------------------------------------------------------------------

package_family_schema = Schema(package_family_schema_dict)


package_schema = Schema(package_schema_dict)


variant_schema = Schema(variant_schema_dict)


# ------------------------------------------------------------------------------
# schemas for converting from POD datatypes
# ------------------------------------------------------------------------------

_commands_schema = Or(SourceCode,       # commands as converted function
                      callable,         # commands as function
                      basestring,       # commands in text block
                      [basestring])     # old-style (rez-1) commands