4848class ValidationProblem (Enum ):
4949 UnitWithoutDocumentation = 1
5050 InvalidEnum = 2
51- MissingRequiredGroup = 3
52- MissingRequiredField = 4
53- MissingRequiredAttribute = 5
54- InvalidType = 6
55- InvalidDatetime = 7
56- IsNotPosInt = 8
57- ExpectedGroup = 9
58- MissingDocumentation = 10
59- MissingUnit = 11
60- ChoiceValidationError = 12
61- UnitWithoutField = 13
62- AttributeForNonExistingField = 14
63- BrokenLink = 15
64- FailedNamefitting = 16
65- NXdataMissingSignalData = 17
66- NXdataMissingAxisData = 18
67- NXdataAxisMismatch = 19
68- KeyToBeRemoved = 20
51+ OpenEnumWithNewItem = 3
52+ MissingRequiredGroup = 4
53+ MissingRequiredField = 5
54+ MissingRequiredAttribute = 6
55+ InvalidType = 7
56+ InvalidDatetime = 8
57+ IsNotPosInt = 9
58+ ExpectedGroup = 10
59+ MissingDocumentation = 11
60+ MissingUnit = 12
61+ ChoiceValidationError = 13
62+ UnitWithoutField = 14
63+ AttributeForNonExistingField = 15
64+ BrokenLink = 16
65+ FailedNamefitting = 17
66+ NXdataMissingSignalData = 18
67+ NXdataMissingAxisData = 19
68+ NXdataAxisMismatch = 20
69+ KeyToBeRemoved = 21
6970
7071
7172class Collector :
@@ -85,7 +86,11 @@ def _log(self, path: str, log_type: ValidationProblem, value: Optional[Any], *ar
8586 )
8687 elif log_type == ValidationProblem .InvalidEnum :
8788 logger .warning (
88- f"The value at { path } should be one of the following: { value } "
89+ f"The value at { path } should be one of the following: { value } ."
90+ )
91+ elif log_type == ValidationProblem .OpenEnumWithNewItem :
92+ logger .info (
93+ f"The value at { path } does not match with the enumerated items from the open enumeration: { value } ."
8994 )
9095 elif log_type == ValidationProblem .MissingRequiredGroup :
9196 logger .warning (f"The required group, { path } , hasn't been supplied." )
@@ -164,7 +169,10 @@ def collect_and_log(
164169 if self .logging and path + str (log_type ) + str (value ) not in self .data :
165170 self ._log (path , log_type , value , * args , ** kwargs )
166171 # info messages should not fail validation
167- if log_type not in (ValidationProblem .UnitWithoutDocumentation ,):
172+ if log_type not in (
173+ ValidationProblem .UnitWithoutDocumentation ,
174+ ValidationProblem .OpenEnumWithNewItem ,
175+ ):
168176 self .data .add (path + str (log_type ) + str (value ))
169177
170178 def has_validation_problems (self ):
@@ -266,7 +274,7 @@ def get_all_parents_for(xml_elem: ET._Element) -> List[ET._Element]:
266274 root = get_appdef_root (xml_elem )
267275 inheritance_chain = []
268276 extends = root .get ("extends" )
269- while extends is not None and extends != "NXobject" :
277+ while extends is not None :
270278 parent_xml_root , _ = get_nxdl_root_and_path (extends )
271279 extends = parent_xml_root .get ("extends" )
272280 inheritance_chain .append (parent_xml_root )
@@ -489,6 +497,15 @@ def contains_uppercase(field_name: Optional[str]) -> bool:
489497 return any (char .isupper () for char in field_name )
490498
491499
500+ def is_variadic (name : str , name_type : str ) -> bool :
501+ """
502+ Determine if a name is variadic based on its nameType.
503+ """
504+ if name :
505+ return False if name_type == "specified" else True
506+ return True
507+
508+
492509def convert_nexus_to_suggested_name (nexus_name ):
493510 """Helper function to suggest a name for a group from its NeXus class."""
494511 if contains_uppercase (nexus_name ):
@@ -646,7 +663,9 @@ def convert_str_to_bool_safe(value: str) -> Optional[bool]:
646663 raise ValueError (f"Could not interpret string '{ value } ' as boolean." )
647664
648665
649- def is_valid_data_field (value : Any , nxdl_type : str , nxdl_enum : list , path : str ) -> Any :
666+ def is_valid_data_field (
667+ value : Any , nxdl_type : str , nxdl_enum : list , nxdl_enum_open : bool , path : str
668+ ) -> Any :
650669 # todo: Check this function and write test for it. It seems the function is not
651670 # working as expected.
652671 """Checks whether a given value is valid according to the type defined in the NXDL.
@@ -688,11 +707,18 @@ def is_valid_data_field(value: Any, nxdl_type: str, nxdl_enum: list, path: str)
688707
689708 # Check enumeration
690709 if nxdl_enum is not None and value not in nxdl_enum :
691- collector .collect_and_log (
692- path ,
693- ValidationProblem .InvalidEnum ,
694- nxdl_enum ,
695- )
710+ if nxdl_enum_open :
711+ collector .collect_and_log (
712+ path ,
713+ ValidationProblem .OpenEnumWithNewItem ,
714+ nxdl_enum ,
715+ )
716+ else :
717+ collector .collect_and_log (
718+ path ,
719+ ValidationProblem .InvalidEnum ,
720+ nxdl_enum ,
721+ )
696722
697723 return value
698724
@@ -871,8 +897,8 @@ def update_and_warn(key: str, value: str):
871897 "https://github.com/FAIRmat-NFDI/nexus_definitions/"
872898 f"blob/{ get_nexus_version_hash ()} " ,
873899 )
874- update_and_warn ("/@NeXus_version " , get_nexus_version ())
875- update_and_warn ("/@HDF5_version " , "." .join (map (str , h5py .h5 .get_libversion ())))
900+ update_and_warn ("/@NeXus_release " , get_nexus_version ())
901+ update_and_warn ("/@HDF5_Version " , "." .join (map (str , h5py .h5 .get_libversion ())))
876902 update_and_warn ("/@h5py_version" , h5py .__version__ )
877903
878904
0 commit comments