schema_interface#

utils.schema_interface.build_schema(schema_def_dict)[source]#

DESCRIPTION:

This function builds a schema provided a Python dictionary containing the variable types and attributes (if necessary); supported schema types are mandatory (e.g., required = True) and optional (e.g., required = False or is not defined within the schema definitions (schema_def_dict key and value pairs.

A YAML-formatted file snippet describing the schema attributes is as follows. :rtype: Dict

  • This is an optional boolean (bool) type variable named

  • variable1 with default value True.

variable1:

required: False type: bool default: True

  • This is a mandatory float type variable named variable2.

variable2:

required: True type: float

  • This is an optional integer (`int) type variable named

  • variable3 with default value 1.

variable3:

type: int default: 1

Parameters:
schema_def_dict: Dict

A Python dictionary containing the schema definition attributes; these contents are collect from a YAML-formatted file containing the respective variables and corresponding attributes and defined above.

Returns:
schema_attr_dict: Dict

A Python dictionary containing the defined schema and the respective attributes.

Raises:
SchemaInterfaceError:
  • raised if an exception is encountered while defining the default value for optional schema attributes; this is most often encountered when a key and value pair corresponding to the attribute default for an optional variable is not defined for the respective schema variable.

utils.schema_interface.check_opts(key, valid_opts, data, check_and=False)[source]#

DESCRIPTION:

This function checks that key and value pair is valid relative to the list of accepted values.

Parameters:
key: str

A Python string specifying the key for which to validate the respective value against list of accepted values.

valid_opts: List

A Python list containing the accepted values.

data: Dict

A Python dictionary containing the key and value pair which to validate.

Keywords:
check_and: bool, optional

A Python boolean valued variable specifying whether to construct the Python schema dictionary using the And attribute; see __andopts__.

Raises:
SchemaInterfaceError:
  • raised if an exception is encountered while validating the schema.

Return type:

None

utils.schema_interface.validate_keys(varkeys, mandkeys)[source]#

DESCRIPTION:

This function checks whether each of the mandatory attribute keys list (mandkeys) are specified in the variable attribute keys list (varkeys).

Parameters:
varkeys: List

A Python list containing the variable attribute keys.

mandkeys: List

A Python list containing mandatory keys to be sought in the variable attribute keys list (varkeys).

Returns:
validate: bool

A Python boolean valued variable specifying whether each of the mandatory keys in mandkeys is within the variable keys list varkeys.

Return type:

bool

utils.schema_interface.validate_opts(cls_schema, cls_opts, ignore_extra_keys=True)[source]#

DESCRIPTION:

This function validates the calling class schema; if the respective schema is not validated an exception will be raised; otherwise this function is passive.

Parameters:
cls_schema: Dict

A Python dictionary containing the calling class schema.

cls_opts: Dict

A Python dictionary containing the options (i.e., parameter arguments, keyword arguments, etc.,) passed to the respective calling class.

Keywords:
ignore_extra_keys: bool, optional

A Python boolean valued variable specifying whether to ignore extra keys that are contained with the Python dictionary containing the schema to be validated (cls_opts).

Raises:
SchemaInterfaceError:
  • raised if an exception is encountered while validating the schema.

Return type:

None

utils.schema_interface.validate_schema(cls_schema, cls_opts, ignore_extra_keys=True, write_table=True, logger_method='info', width=50)[source]#

DESCRIPTION:

This method validates the specified caller method options against the specified schema; schema optional values (denoted as Optional instances) are assigned default values during instances when the caller method options (cls_opts) as not defined a corresponding value.

Parameters:
cls_schema: Dict

A Python dictionary containing the calling class schema.

cls_opts: Dict

A Python dictionary containing the options (i.e., parameter arguments, keyword arguments, etc.,) passed to the respective calling class.

Keywords:
ignore_extra_keys: bool, optional

A Python boolean valued variable specifying whether to ignore extra keys that are contained with the Python dictionary containing the schema to be validated (cls_opts).

write_table: bool, optional

A Python boolean valued variable specifying whether to write the schema attributes table using the specified logger method.

logger_method: str, optional

A Python string specifying the logger method to be usedf to write the schema attributes table.

width: int, optional

A Python integer defining the maximum number of characters (including spaces) for a string; this applies only to instances (if any) of strings to be wrapped among multiple rows of the table.

Returns:
cls_opts: Dict

A Python dictionary containing the options defined upon entry and updated to contain any optional schema default key and value pairs if not specified within the Python dictionary upon entry.

Return type:

Dict