yggdrasil.metaschema.properties package

Submodules

yggdrasil.metaschema.properties.AnyMetaschemaProperties module

class yggdrasil.metaschema.properties.AnyMetaschemaProperties.TemptypeMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘temptype’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison for the ‘temptype’ property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘temptype’ property.

name = 'temptype'
python_types = (<class 'object'>,)
schema = {'description': 'The type of the data for a single message.', 'type': 'schema'}
types = ('any',)
classmethod validate(validator, value, instance, schema)[source]

Validator for JSON schema validation of an instance by this property. If there is not a user provided validate function, the instance will be encoded and then the encoded value will be checked against the provided value using cls.compare.

Parameters:
  • validator (jsonschmea.Validator) – JSON schema validator.

  • value (object) – Value of the property in the schema.

  • instance (object) – Instance to validate.

  • schema (dict) – Schema that instance should be validated against.

Yields:

str – Error messages associated with failed validation.

yggdrasil.metaschema.properties.ArgsMetaschemaProperty module

class yggdrasil.metaschema.properties.ArgsMetaschemaProperty.ArgsMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘args’ property.

classmethod compare(*args, **kwargs)[source]

Comparison method for ‘args’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘args’ property.

classmethod instance2args(instance)[source]

Get input arguments from a class instance.

Parameters:

instance (object) – Instance of a Python class.

Returns:

Input arguments for re-creating the instance.

Return type:

dict

name = 'args'
python_types = (<class 'object'>,)
schema = {'description': 'Arguments required to recreate a class instance.', 'type': 'array'}
types = ('instance',)

yggdrasil.metaschema.properties.ArrayMetaschemaProperties module

class yggdrasil.metaschema.properties.ArrayMetaschemaProperties.LengthMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘length’ property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘length’ 1darray property.

name = 'length'
python_types = (<class 'numpy.ndarray'>, <class 'unyt.array.unyt_array'>)
schema = {'description': 'Number of elements in the 1D array.', 'minimum': 1, 'type': 'number'}
types = ('1darray',)
class yggdrasil.metaschema.properties.ArrayMetaschemaProperties.ShapeMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘shape’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for the ‘shape’ ndarray property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘shape’ ndarray property.

name = 'shape'
python_types = (<class 'numpy.ndarray'>, <class 'unyt.array.unyt_array'>)
schema = {'description': 'Shape of the ND array in each dimension.', 'items': {'minimum': 1, 'type': 'integer'}, 'type': 'array'}
types = ('ndarray',)

yggdrasil.metaschema.properties.ClassMetaschemaProperty module

class yggdrasil.metaschema.properties.ClassMetaschemaProperty.ClassMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘class’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Method to determine compatiblity of one property value with another. This method is not necessarily symmetric in that the second value may not be compatible with the first even if the first is compatible with the second.

Parameters:
  • prop1 (object) – Property value to compare against prop2.

  • prop2 (object) – Property value to compare against.

Yields:

str – Comparision failure messages.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘class’ property.

name = 'class'
python_types = (<class 'object'>,)
schema = {'anyOf': [{'type': 'class'}, {'type': 'array', 'items': {'type': 'class'}, 'minItems': 1}], 'description': 'One or more classes that the object should be an instance of.'}
types = ('instance',)

yggdrasil.metaschema.properties.DefaultProperty module

class yggdrasil.metaschema.properties.DefaultProperty.DefaultMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘default’ property.

name = 'default'
classmethod normalize(normalizer, value, instance, schema)[source]

Normalization method for ‘default’ property.

yggdrasil.metaschema.properties.JSONArrayMetaschemaProperties module

class yggdrasil.metaschema.properties.JSONArrayMetaschemaProperties.ItemsMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘items’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for ‘items’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘items’ container property.

name = 'items'
python_types = (<class 'tuple'>, <class 'list'>, <class 'numpy.ndarray'>, <class 'pandas.core.frame.DataFrame'>)
types = ('array',)

yggdrasil.metaschema.properties.JSONObjectMetaschemaProperties module

class yggdrasil.metaschema.properties.JSONObjectMetaschemaProperties.PropertiesMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘properties’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison method for ‘properties’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘properties’ container property.

name = 'properties'
classmethod normalize(validator, value, instance, schema)[source]

Normalization method for ‘properties’ container property.

classmethod post_validate(validator, value, instance, schema)[source]

Actions performed after validation if normalizing.

python_types = (<class 'dict'>,)
types = ('object',)

yggdrasil.metaschema.properties.KwargsMetaschemaProperty module

class yggdrasil.metaschema.properties.KwargsMetaschemaProperty.KwargsMetaschemaProperty[source]

Bases: ArgsMetaschemaProperty

Property class for ‘kwargs’ property.

classmethod compare(*args, **kwargs)[source]

Comparison method for ‘args’ container property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘kwargs’ property.

classmethod instance2kwargs(instance)[source]

Get input keyword arguments from a class instance.

Parameters:

instance (object) – Instance of a Python class.

Returns:

Input keyword arguments for re-creating the instance.

Return type:

dict

name = 'kwargs'
python_types = (<class 'object'>,)
schema = {'description': 'Keyword arguments required to recreate a class instance.', 'type': 'object'}
types = ('instance',)

yggdrasil.metaschema.properties.MetaschemaProperty module

class yggdrasil.metaschema.properties.MetaschemaProperty.MetaschemaProperty[source]

Bases: object

Base class for adding properties to the metaschema.

Class Attributes:

name (str): Name of the property. [REQUIRED] schema (dict): JSON schema describing valid values for the property.

[REQUIRED]

types (list): Types of instances that the property is valid for.

[AUTOMATED]

python_types (list): Python types of instances that the property is

valid for. [AUTOMATED]

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Method to determine compatiblity of one property value with another. This method is not necessarily symmetric in that the second value may not be compatible with the first even if the first is compatible with the second.

Parameters:
  • prop1 (object) – Property value to compare against prop2.

  • prop2 (object) – Property value to compare against.

Yields:

str – Comparision failure messages.

classmethod encode(instance, typedef=None)[source]

Method to encode the property given the object.

Parameters:
  • instance (object) – Object to get property for.

  • typedef (object, None) – Template value in type definition to use for initializing encoding some cases. Defaults to None and is ignored.

Returns:

Encoded property for instance.

Return type:

object

name = 'base'
classmethod normalize(validator, value, instance, schema)[source]

Method to normalize the instance based on the property value.

Parameters:
  • validator (Validator) – Validator class.

  • value (object) – Property value.

  • instance (object) – Object to normalize.

  • schema (dict) – Schema containing this property.

Returns:

Normalized object.

Return type:

object

classmethod normalize_in_schema(schema)[source]

Method to normalize the entry for this property in a schema.

Parameters:

schema (dict) – Schema to normalize.

Returns:

Normalized schema.

Return type:

dict

classmethod post_validate(validator, value, instance, schema)[source]

Actions performed after validation if normalizing.

python_types = ()
schema = None
types = ()
classmethod validate(validator, value, instance, schema)[source]

Validator for JSON schema validation of an instance by this property. If there is not a user provided validate function, the instance will be encoded and then the encoded value will be checked against the provided value using cls.compare.

Parameters:
  • validator (jsonschmea.Validator) – JSON schema validator.

  • value (object) – Value of the property in the schema.

  • instance (object) – Instance to validate.

  • schema (dict) – Schema that instance should be validated against.

Yields:

str – Error messages associated with failed validation.

classmethod wrapped_validate(validator, value, instance, schema)[source]

Wrapped validator that handles errors produced by the native validate method and ensures that the property is parsed by the base validator and raises the correct error if necessary.

Parameters:
  • *args – All arguments are passed to the validate class method.

  • **kwargs – All keyword arguments are passed to the validate class method.

yggdrasil.metaschema.properties.MetaschemaProperty.create_property(name, schema, encode, validate=None, compare=None, dont_register=False)[source]

Create a new property class.

Parameters:
  • name (str) – Name of the property.

  • schema (dict) – JSON schema describing valid values for the property.

  • encode (function) – Function to encode the property based on a provided instance. The function must take an instance as input and return the value of the property for that instance.

  • validate (function, optional) – Function to determine if an instance is valid under the contraint of this property. The function must take as input a jsonschema validator, a property value, an instance to evaluate, and the schema. The function must return a boolean: True if the instance is valid, False otherwise. See cls.validate for additional information and default behavior.

  • compare (function, optional) – Function to determine if two property values are compatible. The function must take as input two property values and return a boolean: True if the first property is compatible with the second, False otherwise. See cls.compare for additional information and default behavior.

  • dont_register (bool, optional) – If True, the created property will not be registered. Defaults to False.

yggdrasil.metaschema.properties.ScalarMetaschemaProperties module

class yggdrasil.metaschema.properties.ScalarMetaschemaProperties.PrecisionMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘precision’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparison for the ‘precision’ scalar property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘precision’ scalar property.

name = 'precision'
classmethod normalize_in_schema(schema)[source]

Normalization for the ‘precision’ scalar property in a schema.

python_types = (<class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'unyt.array.unyt_array'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'numpy.signedinteger'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'float'>, <class 'int'>, <class 'unyt.array.unyt_quantity'>)
schema = {'description': 'The size (in bits) of each item.', 'minimum': 1, 'type': 'number'}
types = ('ndarray', 'unicode', 'int', 'complex', '1darray', 'uint', 'float', 'scalar', 'bytes')
class yggdrasil.metaschema.properties.ScalarMetaschemaProperties.SubtypeMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘subtype’ property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘subtype’ scalar property.

name = 'subtype'
classmethod normalize_in_schema(schema)[source]

Normalization for the ‘subtype’ scalar property in a schema.

python_types = (<class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'unyt.array.unyt_array'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'numpy.signedinteger'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'float'>, <class 'int'>, <class 'unyt.array.unyt_quantity'>)
schema = {'description': 'The base type for each item.', 'enum': ['bytes', 'complex', 'float', 'int', 'uint', 'unicode'], 'type': 'string'}
types = ('ndarray', 'scalar', '1darray')
class yggdrasil.metaschema.properties.ScalarMetaschemaProperties.UnitsMetaschemaProperty[source]

Bases: MetaschemaProperty

Property class for ‘units’ property.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Comparision for the ‘units’ scalar property.

classmethod encode(instance, typedef=None)[source]

Encoder for the ‘units’ scalar property.

name = 'units'
python_types = (<class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'unyt.array.unyt_array'>, <class 'numpy.complex64'>, <class 'numpy.float32'>, <class 'numpy.signedinteger'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'float'>, <class 'int'>, <class 'unyt.array.unyt_quantity'>)
schema = {'description': 'Physical units.', 'type': 'string'}
types = ('ndarray', 'unicode', 'int', 'complex', '1darray', 'uint', 'float', 'scalar', 'bytes')

yggdrasil.metaschema.properties.TitleMetaschemaProperty module

class yggdrasil.metaschema.properties.TitleMetaschemaProperty.TitleMetaschemaProperty[source]

Bases: MetaschemaProperty

Title property with validation of new properties.

name = 'title'
python_types = (<class 'object'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numbers.Number'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'type'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'NoneType'>, <class 'unyt.array.unyt_array'>, <class 'method'>, <class 'numpy.complex64'>, <class 'tuple'>, <class 'numpy.float32'>, <class 'numpy.signedinteger'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'bool'>, <class 'dict'>, <class 'function'>, <class 'float'>, <class 'int'>, <class 'builtin_function_or_method'>, <class 'unyt.array.unyt_quantity'>, <class 'list'>, <class 'pandas.core.frame.DataFrame'>)
types = ('function', 'uint', 'array', '1darray', 'instance', 'float', 'scalar', 'class', 'ndarray', 'boolean', 'any', 'int', 'number', 'string', 'integer', 'object', 'null', 'unicode', 'complex', 'bytes')

yggdrasil.metaschema.properties.TypeMetaschemaProperty module

class yggdrasil.metaschema.properties.TypeMetaschemaProperty.TypeMetaschemaProperty[source]

Bases: MetaschemaProperty

Type property with validation of new properties.

classmethod compare(prop1, prop2, root1=None, root2=None)[source]

Method to determine compatiblity of one property value with another. This method is not necessarily symmetric in that the second value may not be compatible with the first even if the first is compatible with the second.

Parameters:
  • prop1 (object) – Property value to compare against prop2.

  • prop2 (object) – Property value to compare against.

Yields:

str – Comparision failure messages.

classmethod encode(instance, typedef=None)[source]

Method to encode the property given the object.

Parameters:
  • instance (object) – Object to get property for.

  • typedef (object, None) – Template value in type definition to use for initializing encoding some cases. Defaults to None and is ignored.

Returns:

Encoded property for instance.

Return type:

object

name = 'type'
classmethod normalize(normalizer, value, instance, schema)[source]

Method to normalize the instance based on the property value.

Parameters:
  • normalizer (Normalizer) – Normalizer class.

  • value (object) – Property value.

  • instance (object) – Object to normalize.

  • schema (dict) – Schema containing this property.

Returns:

Normalized object.

Return type:

object

python_types = (<class 'object'>, <class 'numpy.complex256'>, <class 'numpy.float128'>, <class 'numbers.Number'>, <class 'numpy.uint64'>, <class 'numpy.int64'>, <class 'numpy.str_'>, <class 'str'>, <class 'type'>, <class 'numpy.complex128'>, <class 'numpy.float64'>, <class 'numpy.uint32'>, <class 'numpy.unsignedinteger'>, <class 'numpy.int32'>, <class 'numpy.bytes_'>, <class 'NoneType'>, <class 'unyt.array.unyt_array'>, <class 'method'>, <class 'numpy.complex64'>, <class 'tuple'>, <class 'yggdrasil.metaschema.datatypes.ObjMetaschemaType.ObjDict'>, <class 'numpy.float32'>, <class 'numpy.signedinteger'>, <class 'numpy.uint16'>, <class 'numpy.int16'>, <class 'complex'>, <class 'bytes'>, <class 'numpy.ndarray'>, <class 'numpy.float16'>, <class 'numpy.uint8'>, <class 'numpy.int8'>, <class 'bool'>, <class 'dict'>, <class 'function'>, <class 'trimesh.base.Trimesh'>, <class 'float'>, <class 'int'>, <class 'builtin_function_or_method'>, <class 'unyt.array.unyt_quantity'>, <class 'list'>, <class 'yggdrasil.metaschema.datatypes.PlyMetaschemaType.PlyDict'>, <class 'pandas.core.frame.DataFrame'>)
types = ('function', 'uint', 'array', 'schema', '1darray', 'instance', 'float', 'class', 'scalar', 'ply', 'ndarray', 'boolean', 'any', 'int', 'number', 'string', 'integer', 'obj', 'object', 'null', 'unicode', 'complex', 'bytes')

Module contents

class yggdrasil.metaschema.properties.MetaschemaPropertyMeta(name, bases, class_dict)[source]

Bases: type

Meta class for registering properties.

yggdrasil.metaschema.properties.get_metaschema_property(property_name, skip_generic=False)[source]

Get the property class associated with a metaschema property.

Parameters:
  • property_name (str) – Name of property to get class for.

  • skip_generic (bool, optional) – If True and the property dosn’t have a class, None is returned. Defaults to False.

Returns:

Associated property class.

Return type:

MetaschemaProperty

yggdrasil.metaschema.properties.get_registered_properties()[source]

Return a dictionary of registered properties.

Returns:

Registered property/class pairs.

Return type:

dict

yggdrasil.metaschema.properties.register_metaschema_property(prop_class)[source]

Register a schema property.

Parameters:

prop_class (class) – Class to be registered.

Raises:
  • ValueError – If a property class has already been registered under the same name.

  • ValueError – If the base validator already has a validator function for the property and the new property class has a schema defined.

  • ValueError – If the base validator already has a validator function for the property and the validate method on the new property class is not disabled.

  • ValueError – If the property class does not have an entry in the existing metaschema.