diff --git a/src/caosadvancedtools/models/data_model.py b/src/caosadvancedtools/models/data_model.py index 266414893bcdf1ab45ee1345fc549e15f4a66250..7da52788ce030e7a13238fafb0a1b22c68f5ee3b 100644 --- a/src/caosadvancedtools/models/data_model.py +++ b/src/caosadvancedtools/models/data_model.py @@ -149,6 +149,7 @@ class DataModel(dict): ), name=ent.name)) if diff != "": + breakpoint() if verbose: print(diff) any_change = True diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 175f2f7fbfc5408e70e37740d7ae0506d547c628..964cf1f5679b4b9bcdb0654393b21d8cee9b45ad 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -341,6 +341,38 @@ debug : bool, optional f"invalid keyword in line {entity['__line__']}:", 1) raise ValueError(err_str, *err.args[1:]) from err + # Update properties that are part of record types: + # e.g. add their datatypes, units etc.. + # Otherwise comparison of existing models and the parsed model become difficult. + for name, ent in self.model.items(): + if not isinstance(ent, db.RecordType): + continue + props = ent.get_properties() + for prop in props: + if prop.name in self.model: + model_prop = self.model[prop.name] + # The information must be missing, we don't want to overwrite it accidentally: + if prop.datatype is not None and prop.datatype != model_prop.datatype: + # breakpoint() + raise RuntimeError("datatype must not be set, here. This is probably a bug.") + if prop.unit is not None and prop.unit != model_prop.unit: + # continue + raise RuntimeError("unit must not be set, here. This is probably a bug.") + if prop.description is not None and prop.description != model_prop.description: + # continue + raise RuntimeError("description must not be set, here. This is probably a bug.") + + # If this property has a more detailed definition in the model, + # copy over the information: + + if isinstance(model_prop, db.RecordType): + # in this case the datatype equals the name of the record type: + prop.datatype = prop.name + else: + prop.datatype = model_prop.datatype + prop.unit = model_prop.unit + prop.description = model_prop.description + return DataModel(self.model.values()) @staticmethod @@ -470,6 +502,7 @@ debug : bool, optional """ for n, e in props.items(): + if n in KEYWORDS: if n in KEYWORDS_IGNORED: continue @@ -543,6 +576,13 @@ debug : bool, optional if name in self.treated: raise TwiceDefinedException(name) + # for reducing a little bit of code duplication: + importance_dict = { + "recommended_properties": db.RECOMMENDED, + "obligatory_properties": db.OBLIGATORY, + "suggested_properties": db.SUGGESTED + } + for prop_name, prop in definition.items(): if prop_name == "__line__": continue @@ -558,26 +598,14 @@ debug : bool, optional # Handled above continue - elif prop_name == "recommended_properties": - self._add_to_recordtype( - name, prop, importance=db.RECOMMENDED) - - for n, e in prop.items(): - self._treat_entity(n, e) - - elif prop_name == "obligatory_properties": - self._add_to_recordtype( - name, prop, importance=db.OBLIGATORY) - - for n, e in prop.items(): - self._treat_entity(n, e) - - elif prop_name == "suggested_properties": - self._add_to_recordtype( - name, prop, importance=db.SUGGESTED) + elif prop_name in importance_dict: + for imp_name, imp_val in importance_dict.items(): + if prop_name == imp_name: + self._add_to_recordtype( + name, prop, importance=imp_val) - for n, e in prop.items(): - self._treat_entity(n, e) + for n, e in prop.items(): + self._treat_entity(n, e) # datatype is already set elif prop_name == "datatype":