1414from hed .errors .error_types import SchemaWarnings , ValidationErrors , SchemaAttributeErrors
1515from hed .errors .error_reporter import ErrorHandler
1616from hed .schema .hed_cache import get_hed_versions
17- from hed .schema .hed_schema_constants import HedKey , character_types
17+ from hed .schema .hed_schema_constants import HedKey , character_types , HedSectionKey
1818from hed .schema .schema_validation_util import schema_version_for_library
1919from semantic_version import Version
2020
@@ -39,6 +39,36 @@ def tag_is_placeholder_check(hed_schema, tag_entry, attribute_name):
3939 return issues
4040
4141
42+ def attribute_is_deprecated (hed_schema , tag_entry , attribute_name ):
43+ """ Check if the attribute is deprecated.
44+
45+ does not check value.
46+
47+ Parameters:
48+ hed_schema (HedSchema): The schema to use for validation
49+ tag_entry (HedSchemaEntry): The schema entry for this tag.
50+ attribute_name (str): The name of this attribute
51+
52+ Returns:
53+ list: A list of issues. Each issue is a dictionary.
54+ """
55+ issues = []
56+ # Attributes has to check properties
57+ section_key = HedSectionKey .Attributes
58+ if tag_entry .section_key == HedSectionKey .Attributes :
59+ section_key = HedSectionKey .Properties
60+
61+ attribute_entry = hed_schema .get_tag_entry (attribute_name , section_key )
62+ if (attribute_entry and attribute_entry .has_attribute (HedKey .DeprecatedFrom )
63+ and not tag_entry .has_attribute (HedKey .DeprecatedFrom )):
64+ issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_ATTRIBUTE_VALUE_DEPRECATED ,
65+ tag_entry .name ,
66+ attribute_entry .name ,
67+ attribute_name )
68+
69+ return issues
70+
71+
4272# todo: This needs to be refactored, these next several functions are near identical
4373def tag_exists_check (hed_schema , tag_entry , attribute_name ):
4474 """ Check if the list of possible tags exists in the schema.
@@ -56,11 +86,18 @@ def tag_exists_check(hed_schema, tag_entry, attribute_name):
5686 possible_tags = tag_entry .attributes .get (attribute_name , "" )
5787 split_tags = possible_tags .split ("," )
5888 for org_tag in split_tags :
59- if org_tag and org_tag not in hed_schema .tags :
89+ org_entry = hed_schema .tags .get (org_tag )
90+ if org_tag and not org_entry :
6091 issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_SUGGESTED_TAG_INVALID ,
6192 tag_entry .name ,
6293 org_tag ,
6394 attribute_name )
95+ elif (org_entry and org_entry .has_attribute (HedKey .DeprecatedFrom )
96+ and not tag_entry .has_attribute (HedKey .DeprecatedFrom )):
97+ issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_ATTRIBUTE_VALUE_DEPRECATED ,
98+ tag_entry .name ,
99+ org_tag ,
100+ attribute_name )
64101
65102 return issues
66103
@@ -70,11 +107,18 @@ def unit_class_exists(hed_schema, tag_entry, attribute_name):
70107 possible_unit_classes = tag_entry .attributes .get (attribute_name , "" )
71108 split_tags = possible_unit_classes .split ("," )
72109 for org_tag in split_tags :
73- if org_tag and org_tag not in hed_schema .unit_classes :
110+ unit_class_entry = hed_schema .unit_classes .get (org_tag )
111+ if org_tag and not unit_class_entry :
74112 issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_UNIT_CLASS_INVALID ,
75113 tag_entry .name ,
76114 org_tag ,
77115 attribute_name )
116+ elif (unit_class_entry and unit_class_entry .has_attribute (HedKey .DeprecatedFrom )
117+ and not tag_entry .has_attribute (HedKey .DeprecatedFrom )):
118+ issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_ATTRIBUTE_VALUE_DEPRECATED ,
119+ tag_entry .name ,
120+ org_tag ,
121+ attribute_name )
78122
79123 return issues
80124
@@ -83,24 +127,38 @@ def value_class_exists(hed_schema, tag_entry, attribute_name):
83127 issues = []
84128 possible_value_classes = tag_entry .attributes .get (attribute_name , "" )
85129 split_tags = possible_value_classes .split ("," )
130+
86131 for org_tag in split_tags :
87- if org_tag and org_tag not in hed_schema .value_classes :
132+ value_class_entry = hed_schema .value_classes .get (org_tag )
133+ if org_tag and not value_class_entry :
88134 issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_VALUE_CLASS_INVALID ,
89135 tag_entry .name ,
90136 org_tag ,
91137 attribute_name )
138+ elif (value_class_entry and value_class_entry .has_attribute (HedKey .DeprecatedFrom )
139+ and not tag_entry .has_attribute (HedKey .DeprecatedFrom )):
140+ issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_ATTRIBUTE_VALUE_DEPRECATED ,
141+ tag_entry .name ,
142+ org_tag ,
143+ attribute_name )
92144
93145 return issues
94146
95147
96148def unit_exists (hed_schema , tag_entry , attribute_name ):
97149 issues = []
98- default_unit = tag_entry .attributes .get (attribute_name , "" )
99- if default_unit and default_unit not in tag_entry .derivative_units :
150+ unit = tag_entry .attributes .get (attribute_name , "" )
151+ unit_entry = tag_entry .derivative_units .get (unit )
152+ if unit and not unit_entry :
100153 issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_DEFAULT_UNITS_INVALID ,
101154 tag_entry .name ,
102- default_unit ,
155+ unit ,
103156 tag_entry .units )
157+ elif (unit_entry and unit_entry .has_attribute (HedKey .DeprecatedFrom )
158+ and not tag_entry .has_attribute (HedKey .DeprecatedFrom )):
159+ issues += ErrorHandler .format_error (SchemaAttributeErrors .SCHEMA_DEFAULT_UNITS_DEPRECATED ,
160+ tag_entry .name ,
161+ unit_entry .name )
104162
105163 return issues
106164
0 commit comments