schema_compare

Functions supporting comparison of schemas.

Functions

compare_differences(schema1, schema2[, ...])

Compare the tags in two schemas, this finds any differences

compare_schemas(schema1, schema2[, ...])

Compare two schemas section by section.

find_matching_tags(schema1, schema2[, ...])

Compare the tags in two library schemas.

gather_schema_changes(schema1, schema2[, ...])

Compare two schemas section by section, generating a changelog

pretty_print_change_dict(change_dict[, ...])

Formats the change_dict into a string.

compare_differences(schema1, schema2, attribute_filter=None, title='')[source]

Compare the tags in two schemas, this finds any differences

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • attribute_filter (str, optional) – The attribute to filter entries by. Entries without this attribute are skipped. The most common use would be HedKey.InLibrary If it evaluates to False, no filtering is performed.

  • title (str) – Optional header to add, a default on will be added otherwise.

Returns:

the changes listed out by section

Return type:

changelog(str)

compare_schemas(schema1, schema2, attribute_filter='inLibrary', sections=(<HedSectionKey.Tags: 'tags'>, ))[source]

Compare two schemas section by section.

The function records matching entries, entries present in one schema but not in the other, and unequal entries.

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • attribute_filter (str, optional) – The attribute to filter entries by. Entries without this attribute are skipped. The most common use would be HedKey.InLibrary If it evaluates to False, no filtering is performed.

  • sections (list or None) – the list of sections to compare. By default, just the tags section. If None, checks all sections including header, prologue, and epilogue.

Returns:

A tuple containing four dictionaries: - matches(dict): Entries present in both schemas and are equal. - not_in_schema1(dict): Entries present in schema2 but not in schema1. - not_in_schema2(dict): Entries present in schema1 but not in schema2. - unequal_entries(dict): Entries present in both schemas but are not equal.

Return type:

tuple

find_matching_tags(schema1, schema2, sections=(<HedSectionKey.Tags: 'tags'>, ), return_string=True)[source]

Compare the tags in two library schemas. This finds tags with the same term.

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • sections (list) – the list of sections to compare. By default, just the tags section. If None, checks all sections including header, prologue, and epilogue.

  • return_string (bool) – If False, returns the raw python dictionary(for tools etc. possible use)

Returns:

Returns a formatted string or python dict

Return type:

str or dict

gather_schema_changes(schema1, schema2, attribute_filter=None)[source]

Compare two schemas section by section, generating a changelog

Parameters:
  • schema1 (HedSchema) – The first schema to be compared.

  • schema2 (HedSchema) – The second schema to be compared.

  • attribute_filter (str, optional) – The attribute to filter entries by. Entries without this attribute are skipped. The most common use would be HedKey.InLibrary If it evaluates to False, no filtering is performed.

Returns:

A dict organized by section with the changes

Return type:

changelog(dict)

pretty_print_change_dict(change_dict, title='Schema changes', use_markdown=True)[source]

Formats the change_dict into a string.

Parameters:
  • change_dict (dict) – The result from calling gather_schema_changes

  • title (str) – Optional header to add, a default on will be added otherwise.

  • use_markdown (bool) – If True, adds Markdown formatting characters to output.

Returns:

the changes listed out by section

Return type:

changelog(str)