yawning_titan.config.core#
Classes
Used to provide helper methods to represent a ConfigGroup object. |
|
The ConfigGroup class holds a ConfigItem's, doc, properties, and a ConfigItemValidation. |
|
Used to return a validation result for a group of dependant config items, and the list of item validations. |
|
The ConfigItem class holds an items value, doc, and properties. |
|
Create |
|
The base validation methods for a config element. |
|
An Abstract Base Class that is inherited by config data type properties. |
- class yawning_titan.config.core.ConfigBase[source]#
Used to provide helper methods to represent a ConfigGroup object.
- get_config_elements(types=None)[source]#
Get the attributes of the class that are either :class: ConfigGroup or
ConfigItem
.- Parameters:
_type – An optional type for a specific type of config element.
- Returns:
A dictionary of names to config elements.
- get_non_config_elements()[source]#
Get all attributes of the class that are not :class: ConfigGroup or :class: ConfigItem.
- Returns:
A dictionary of names to attributes.
- property config_items#
~yawning_titan.config.core.ConfigItem children of the group.
- Type:
Property to represent the
- Type:
class
- property config_groups#
~yawning_titan.config.core.ConfigGroup children of the group.
- Type:
Property to represent the
- Type:
class
- class yawning_titan.config.core.ItemTypeProperties(_allowed_types=None, allow_null=None, default=None)[source]#
An Abstract Base Class that is inherited by config data type properties.
- allow_null = None#
True if the config _value can be left empty, otherwise False.
- default = None#
The items default value.
- validate(val)[source]#
Perform the base validation checks common to all ConfigItem elements.
These checks include: - Check that the value is not null if :attribute: allow_null is False - Check that the type of the value is in :attribute: allowed_types
- __init__(_allowed_types=None, allow_null=None, default=None)#
- class yawning_titan.config.core.ConfigValidationBase(fail_reasons=None, fail_exceptions=None)[source]#
The base validation methods for a config element.
- add_validation(fail_reason, exception)[source]#
Add a validation fail_reason, exception pair to their respective lists.
Additionally check that no such error already exists.
- Parameters:
fail_reason – A string message to describe a particular error.
exception – A wrapped Exception object that can be used to raise an error for the fail_reason.
- abstract property passed#
fail_reasons or :attribute: fail_exceptions.
- Returns:
A bool.
- Type:
Returns True if there are no
- Type:
attribute
- class yawning_titan.config.core.ConfigItemValidation(fail_reasons=None, fail_exceptions=None)[source]#
Create
ConfigItemValidation
fromConfigValidationBase
.- property passed#
fail_reasons or :attribute: fail_exceptions.
- Returns:
A bool.
- Type:
Returns True if there are no
- Type:
attribute
- class yawning_titan.config.core.ConfigGroupValidation(fail_reasons=None, fail_exceptions=None)[source]#
Used to return a validation result for a group of dependant config items, and the list of item validations.
If validation fails, a reason why and any exception raised are returned.
- add_element_validation(element_name, validation)[source]#
Add a
ConfigItemValidation
orConfigGroupValidation
to the item validation dict.- Parameters:
element_name – The name of the element.
validation – the instance of ConfigItemValidation.
- to_dict(element_name='root', root=True)[source]#
Express the error tree as a dictionary.
- Parameters:
element_name – A string name for the element to be represented.
- Returns:
A dict of element names to validation errors or validation dictionaries.
- log(element_name='root')[source]#
Return the validation results as a formatted string.
- Parameters:
element_name – A string name for the element to be represented.
- property passed#
fail_reasons or :attribute: fail_exceptions and the group passed.
The group validation has passed and all element validation has passed.
- Returns:
A bool.
- Type:
Returns True if there are no
- Type:
attribute
- property group_passed#
fail_reasons or :attribute: fail_exceptions.
- Returns:
A bool.
- Type:
Returns True if there are no
- Type:
attribute
- property element_validation#
The dict of element to
ConfigItemValidation
andConfigGroupValidation
validations.- Returns:
A dict.
- property elements_passed#
Returns True if all items passed validation, otherwise returns False.
- Returns:
A bool.
- class yawning_titan.config.core.ConfigItem(value, doc=None, alias=None, depends_on=<factory>, properties=None, validation=None)[source]#
The ConfigItem class holds an items value, doc, and properties.
- value#
The items value.
- doc = None#
The items doc.
- alias = None#
The alias of the config item, i.e. its representation from the original config.
- depends_on#
ConfigItem’s upon which this item depends. If these items are set so must this item be.
- Type:
A list of
- Type:
class
- properties = None#
The items properties.
- validation = None#
The instance of ConfigItemValidation that provides access to the item validation details.
- to_dict(as_key_val_pair=False, values_only=False, include_none=True)[source]#
Return the ConfigItem as a dict.
- Parameters:
as_key_val_pair – If true, the dict is returned as a value in a key/value pair, the key being the class name.
- Returns:
The ConfigItem as a dict.
- validate()[source]#
Validate the item against its properties.
If no properties exist, simply return a default passed
ConfigItemValidation
.- Returns:
An instance of
ConfigItemValidation
.
- set_value(value)[source]#
Set the value of the
ConfigItem
bypassing the validation.- Parameters:
value – The value to be set.
- __init__(value, doc=None, alias=None, depends_on=<factory>, properties=None, validation=None)#
- class yawning_titan.config.core.ConfigGroup(doc=None)[source]#
The ConfigGroup class holds a ConfigItem’s, doc, properties, and a ConfigItemValidation.
The ConfigGroup constructor.
- Parameters:
doc – The groups doc.
- validate(raise_overall_exception=False)[source]#
Validate the grouped items against their properties.
- Returns:
An instance of
ConfigGroupValidation
.
- to_dict(values_only=False, legacy=False, include_none=True)[source]#
Return the ConfigGroup as a dict.
- Parameters:
values_only – Create a dictionary containing only the value of :class: ConfigItem’s
legacy – Convert the group into a unitary depth dictionary of legacy config value (aliases) to :class: ConfigItem’s by calling :method: ConfigGroup.to_legacy.
- Returns:
The ConfigGroup as a dict.
- to_legacy_dict(flattened_dict=None)[source]#
Convert the group into a unitary depth dictionary of legacy config value (aliases) to :class: ConfigItem’s.
- Returns:
a dictionary
- to_yaml(file_path)[source]#
Save the values of the elements of the group to a .yaml file.
- Parameters:
file_path – The path to the .yaml file
- set_from_dict(config_dict, legacy=False, infer_legacy=False, **kwargs)[source]#
Set the values of all :class: ConfigGroup or
ConfigItem
elements.- Parameters:
config_dict – A dictionary representing values of all config elements.
legacy – Whether to use the alias names for config elements to construct the config from a legacy dictionary.
infer_legacy – Attempt to recognise if a config is of a legacy type.
- kwargs can contain 2 parameters:
- root: Whether the element is a base level element or not.
if the element is a root then it should validate all of its descendants.
legacy_lookup: The current flattened dictionary representation of the class by its legacy keys.
- set_from_yaml(file_path, legacy=False, infer_legacy=False)[source]#
Set the elements of the group from a .yaml file.
- Parameters:
file_path – The path to the .yaml file.
legacy – Whether to use the alias names for config elements to construct the config from a legacy dictionary.
infer_legacy – Attempt to recognise if a config is of a legacy type.