From dd637a408f32ae4ba2dae6bd6799c1fca368b7e8 Mon Sep 17 00:00:00 2001 From: Alexander Schlemmer <a.schlemmer@indiscale.com> Date: Mon, 18 Nov 2024 11:51:39 +0100 Subject: [PATCH] FIX(yaml-model-parser): add datatype and other missing attributes to properties belonging to record types in data model --- src/caosadvancedtools/models/parser.py | 70 +++++++++++++------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index b3c5c7e2..27505329 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -37,18 +37,17 @@ to be a list with the names. Here, NO NEW entities can be defined. """ import argparse import json -import jsonref import re import sys -import yaml - from typing import List, Optional from warnings import warn +import jsonref import jsonschema import linkahead as db - +import yaml from linkahead.common.datatype import get_list_datatype + from .data_model import LINKAHEAD_INTERNAL_PROPERTIES, DataModel # Keywords which are allowed in data model descriptions. @@ -341,38 +340,37 @@ debug : bool, optional f"invalid keyword in line {entity['__line__']}:", 1) raise ValueError(err_str, *err.args[1:]) from err - # TODO: functionality commented out, to be able to test failing test first. - # 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 +# 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()) -- GitLab