Skip to content

Commit

Permalink
Completely re-write schema comparison summary
Browse files Browse the repository at this point in the history
Now generates a changelog based on the Major/Minor/Patch changes
Fix issues with name for withStandard schema
Improve comparison between schema entries to handle inherited attributes
  • Loading branch information
IanCa committed Feb 8, 2024
1 parent d6f3b73 commit 392a881
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 351 deletions.
22 changes: 13 additions & 9 deletions hed/schema/hed_schema_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ def section_key(self):
def __eq__(self, other):
if self.name != other.name:
return False
if self.attributes != other.attributes:
# We only want to compare known attributes
self_attr = self.get_known_attributes()
other_attr = other.get_known_attributes()
# We can no longer be sure on the order of attribute values, since owl formatting has no order
if self_attr != other_attr and not self._compare_attributes_no_order(self_attr, other_attr):
return False
if not self._compare_attributes_no_order(self.attributes, other.attributes):
return False
if self.description != other.description:
return False
return True
Expand All @@ -138,8 +133,9 @@ def get_known_attributes(self):

@staticmethod
def _compare_attributes_no_order(left, right):
left = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in left.items()}
right = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in right.items()}
if left != right:
left = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in left.items()}
right = {name: (set(value.split(",")) if isinstance(value, str) else value) for (name, value) in right.items()}

return left == right

Expand Down Expand Up @@ -235,6 +231,7 @@ def get_conversion_factor(self, unit_name):
if HedKey.ConversionFactor in self.attributes:
return float(self.derivative_units.get(unit_name))


class HedTagEntry(HedSchemaEntry):
""" A single tag entry in the HedSchema. """
def __init__(self, *args, **kwargs):
Expand All @@ -252,6 +249,13 @@ def __init__(self, *args, **kwargs):
# Descendent tags below this one
self.children = {}

def __eq__(self, other):
if not super().__eq__(other):
return False
if not self._compare_attributes_no_order(self.inherited_attributes, other.inherited_attributes):
return False
return True

def has_attribute(self, attribute, return_value=False):
""" Returns th existence or value of an attribute in this entry.
Expand Down
Loading

0 comments on commit 392a881

Please sign in to comment.