Skip to content
Snippets Groups Projects

REL: Release 0.10.0

Merged Florian Spreckelsen requested to merge release-0.10.0 into main
1 file
+ 20
5
Compare changes
  • Side-by-side
  • Inline
@@ -180,16 +180,20 @@ Returns
out: tuple
- the final value of the property; variable names contained in `values` are replaced.
- the final unit of the property; variable names contained in `values` are replaced.
- the collection mode (can be single, list or multiproperty)
"""
# @review Florian Spreckelsen 2022-05-13
propunit = None
if isinstance(value, dict):
if "value" not in value:
# TODO: how do we handle this case? Just ignore?
# or disallow?
raise NotImplementedError(f"This definition has no \"value\": {value}")
propvalue = value["value"]
if "unit" in value:
propunit = value["unit"]
# can be "single", "list" or "multiproperty"
collection_mode = value["collection_mode"]
elif isinstance(value, str):
@@ -226,7 +230,9 @@ out: tuple
return (propvalue, collection_mode)
propvalue = replace_variables(propvalue, values)
return (propvalue, collection_mode)
if propunit:
propunit = replace_variables(propunit, values)
return (propvalue, propunit, collection_mode)
def create_records(values: GeneralStore, records: RecordStore, def_records: dict):
@@ -277,7 +283,7 @@ def create_records(values: GeneralStore, records: RecordStore, def_records: dict
key = key_template.safe_substitute(**values.get_storage())
keys_modified.append((name, key))
propvalue, collection_mode = handle_value(value, values)
propvalue, propunit, collection_mode = handle_value(value, values)
if key.lower() in SPECIAL_PROPERTIES:
# e.g. description, name, etc.
@@ -291,17 +297,26 @@ def create_records(values: GeneralStore, records: RecordStore, def_records: dict
else:
if c_record.get_property(key) is None:
if collection_mode == "list":
c_record.add_property(name=key, value=[propvalue])
c_record.add_property(name=key, value=[propvalue], unit=propunit)
elif (collection_mode == "multiproperty" or
collection_mode == "single"):
c_record.add_property(name=key, value=propvalue)
c_record.add_property(name=key, value=propvalue, unit=propunit)
else:
if collection_mode == "list":
if propunit and c_record.get_property(key).unit and propunit != c_record.get_property(key).unit:
raise RuntimeError(
f"Property '{key}' has contradictory units: "
f"{propunit} and {c_record.get_property(key).unit}"
)
c_record.get_property(key).value.append(propvalue)
if propunit and not c_record.get_property(key).unit:
c_record.get_property(key).unit = propunit
elif collection_mode == "multiproperty":
c_record.add_property(name=key, value=propvalue)
c_record.add_property(name=key, value=propvalue, unit=propunit)
elif collection_mode == "single":
c_record.get_property(key).value = propvalue
if propunit:
c_record.get_property(key).unit = propunit
# no matter whether the record existed in the record store or not,
# parents will be added when they aren't present in the record yet:
Loading