merge_hierarchies.py

merge_hierarchies.py#

aviary.utils.merge_hierarchies.merge_attributes(base_class, merge_class, base_class_attributes, merge_class_attributes)[source]

Adds unique attributes of merge_class to base_class.

For all the attributes of merge_class that are not present in base_class we add them to base_class. Attributes present in both classes are ignored because if they are variables they have already been checked and found identical and if they are inner classes they will be addressed on a recursive call to this function. Attributes present only in base_class are ignored because we are adding to base_class and thus all of its features are automatically preserved.

Parameters:
  • base_class (class) – A class that is all or part of a variable hierarchy. This can be the top=level class in the hierarchy, or any inner class nested at any depth within that top-level class.

  • merge_class (class) – A class that is all or part of a variable hierarchy. This can be the top=level class in the hierarchy, or any inner class nested at any depth within that top-level class.

  • base_class_attributes (set of strings) – A set of the name of all attributes (either variables, inner classes, or both) of base_class.

  • merge_class_attributes (set of strings) – A set of the name of all attributes (either variables, inner classes, or both) of merge_class.

Returns:

base_class – A class that contains the merged together attributes of base_class and merge_class, with the exception that inner class base_class and merge_class share which have diverging attributes inside of them are not necessarily included.

Return type:

class

Raises:

None – No exceptions raised by this method, although other methods called within may raise exceptions.

aviary.utils.merge_hierarchies.merge_hierarchies(hierarchies_to_merge)[source]

Combines all provided variable hierarchies into one unified variable hierarchy.

Performs checks on the user-provided list of variable hierarchies in order to ensure that they are compatible for merge. Ensures that they are not derived from different superclasses, and that they do not have conflicting values. Assuming all checks pass, the provided hierarchies are combined into a single hierarchy.

Parameters:

hierarchies_to_merge (list of classes) – This is a list of all the variable hierarchies which should be merged into a single hierarchy. This list should not include hierarchies of multiple types (i.e. an av.Mission hierarchy extension should not be mixed with an av.Aircraft hierarchy extension)

Returns:

merged_hierarchy – Aviary variable hierarchy that includes all the variables present in the inputted hierarchy list. Duplicates have been removed, and conflicting duplicates are not possible.

Return type:

class

Raises:

ValueError – Raises an exception if the list of inputted variable hierarchies includes hierarchies that have been subclassed from different superclasses.

aviary.utils.merge_hierarchies.merge_two_hierarchies(base_hierarchy, hierarchy_b)[source]

Merge two variable hierarchies together by adding the second into the first.

Add the attributes (variables and inner classes) of two variable hierarchies together, so that the attributes that are unique to each hierarchy are combined in the resultant hierarchy. This is accomplished by adding on to the first of the two provided hierarchies, and returning it.

Parameters:
  • base_hierarchy (class) – An Aviary variable hierarchy. This hierarchy will function as the ‘base’ hierarchy, which is the hierarchy that has attributes added onto it from another hierarchy in order to combine the attributes of the base and the other hierarchy.

  • hierarchy_b (class) – An Aviary variable hierarchy. This hierarchy will function as the ‘auxiliary’ hierarhcy, which is the hierarchy whose unique attributes are added onto a base in order to combine the attributes of the base and the auxiliary.

Returns:

base_hierarchy – An Aviary variable hierarchy which includes both the attributes of the inputted base_hierarchy and hierarchy_b. This is the same object as the inputted base_hierarchy and has been updated through mutability.

Return type:

class

Raises:

None – No exceptions raised by this method, although other methods called within may raise exceptions.

aviary.utils.merge_hierarchies.recursive_merge(overlapping_inners, base_class, merge_class)[source]

Recursively compares all inner classes to an infinite depth and identifies mismatched string-named values.

For all of the inner class names provided in overlapping_inner_classes this function calls compare_inner_classes and compares those inner classes recursively until it reaches the full depth to which outer_class_a and outer_class_b have any inner classes in common.

Parameters:
  • overlapping_inner_classes (set of strings) – This is a set of strings where each string is the name of an inner class that outer_class_a and outer_class_b have in common.

  • outer_class_a (class) – A class that is all or part of a variable hierarchy. This can be the top-level class in the hierarchy, or any inner class nested at any depth within that top-level class.

  • outer_class_b (class) – A class that is all or part of a variable hierarchy. This can be the top-level class in the hierarchy, or any inner class nested at any depth within that top-level class.

Returns:

No variables returned by this method.

Return type:

None

Raises:

None – No exceptions raised by this method, although other methods called within may raise exceptions.