diff --git a/CHANGELOG.md b/CHANGELOG.md index ea860b1d9720742d696d8d0d48cb399ba9ef2dfd..58cd56df3225eee536b35a8e0c32f3a6475f3e00 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ## ### Added ### + - You can now use `python -m caosadvancedtools.models.parser model_file` to parse and potentially synchronize data models. @@ -14,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Deprecated ### +- [#36](https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/36) + `parent` keyword in yaml datamodel definition (replaced by + `inherit_from_{obligatory|recommended|suggested}` keywords). + ### Removed ### ### Fixed ### diff --git a/src/caosadvancedtools/models/parser.py b/src/caosadvancedtools/models/parser.py index 25fe83d9b2a0afc2533fdcd46f72a990348cf4e0..c9b890de570d29e4a013b14ebe4579e956277ed2 100644 --- a/src/caosadvancedtools/models/parser.py +++ b/src/caosadvancedtools/models/parser.py @@ -42,6 +42,7 @@ import sys import yaml from typing import List +from warnings import warn import jsonschema import caosdb as db @@ -519,6 +520,16 @@ class Parser(object): self._inherit(name, prop, db.RECOMMENDED) elif prop_name == "inherit_from_suggested": self._inherit(name, prop, db.SUGGESTED) + elif prop_name == "parent": + warn( + DeprecationWarning( + "The `parent` keyword is deprecated and will be " + "removed in a future version. Use " + "`inherit_from_{obligatory|recommended|suggested}` " + "instead." + ) + ) + self._inherit(name, prop, db.OBLIGATORY) else: raise ValueError("invalid keyword: {}".format(prop_name)) diff --git a/src/doc/yaml_interface.rst b/src/doc/yaml_interface.rst index f5dea11acc3a23c3d6eb9680e1c3e488c4b43a54..78ff4cdd6fee201c7ebe17977f497b84e9657aa2 100644 --- a/src/doc/yaml_interface.rst +++ b/src/doc/yaml_interface.rst @@ -109,7 +109,7 @@ Keywords added as parents, and all Properties with at least the importance ``XXX`` are inherited. For example, ``inherited_from_recommended`` will inherit all Properties of importance ``recommended`` and ``obligatory``, but not ``suggested``. -- **parent**: Parent of this entity. (*Deprecated*) +- **parent**: Parent of this entity. Same as ``inherit_from_obligatory``. (*Deprecated*) Usage ===== diff --git a/unittests/test_yaml_model_parser.py b/unittests/test_yaml_model_parser.py index a9f072b754618e38237cbf70e74c7944551f1045..6cdea7922a8503be082e8947edecd7e8c849730b 100644 --- a/unittests/test_yaml_model_parser.py +++ b/unittests/test_yaml_model_parser.py @@ -1,7 +1,7 @@ import unittest from datetime import date from tempfile import NamedTemporaryFile -from pytest import raises +from pytest import deprecated_call, raises import caosdb as db from caosadvancedtools.models.parser import (TwiceDefinedException, @@ -474,3 +474,40 @@ F: """ with raises(NotImplementedError): entities = parse_model_from_string(model) + + +def test_issue_36(): + """Test whether the `parent` keyword is deprecated. + + See https://gitlab.com/caosdb/caosdb-advanced-user-tools/-/issues/36. + + """ + model_string = """ +R1: + obligatory_properties: + prop1: + datatype: TEXT +R2: + obligatory_properties: + prop2: + datatype: TEXT + recommended_properties: + prop3: + datatype: TEXT +R3: + parent: + - R2 + inherit_from_obligatory: + - R1 +""" + with deprecated_call(): + # Check whether this is actually deprecated + model = parse_model_from_string(model_string) + + assert "R3" in model + r3 = model["R3"] + assert isinstance(r3, db.RecordType) + for par in ["R1", "R2"]: + # Until removal, both do the same + assert has_parent(r3, par) + assert r3.get_parent(par)._flags["inheritance"] == db.OBLIGATORY