Skip to content
Snippets Groups Projects
Commit be6e2a63 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

Merge branch 'f-deprecate-parent-keyword' into 'dev'

MAINT: Deprecate `parent` keyword in yaml datamodel

See merge request !53
parents e6c0faac 28d118f4
No related branches found
No related tags found
2 merge requests!54REL: Release 0.5.0,!53MAINT: Deprecate `parent` keyword in yaml datamodel
Pipeline #27922 passed
...@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## ## [Unreleased] ##
### Added ### ### Added ###
- You can now use `python -m caosadvancedtools.models.parser model_file` to - You can now use `python -m caosadvancedtools.models.parser model_file` to
parse and potentially synchronize data models. parse and potentially synchronize data models.
...@@ -14,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -14,6 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated ### ### 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 ### ### Removed ###
### Fixed ### ### Fixed ###
......
...@@ -42,6 +42,7 @@ import sys ...@@ -42,6 +42,7 @@ import sys
import yaml import yaml
from typing import List from typing import List
from warnings import warn
import jsonschema import jsonschema
import caosdb as db import caosdb as db
...@@ -519,6 +520,16 @@ class Parser(object): ...@@ -519,6 +520,16 @@ class Parser(object):
self._inherit(name, prop, db.RECOMMENDED) self._inherit(name, prop, db.RECOMMENDED)
elif prop_name == "inherit_from_suggested": elif prop_name == "inherit_from_suggested":
self._inherit(name, prop, db.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: else:
raise ValueError("invalid keyword: {}".format(prop_name)) raise ValueError("invalid keyword: {}".format(prop_name))
......
...@@ -109,7 +109,7 @@ Keywords ...@@ -109,7 +109,7 @@ Keywords
added as parents, and all Properties with at least the importance ``XXX`` are inherited. For 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`` example, ``inherited_from_recommended`` will inherit all Properties of importance ``recommended``
and ``obligatory``, but not ``suggested``. and ``obligatory``, but not ``suggested``.
- **parent**: Parent of this entity. (*Deprecated*) - **parent**: Parent of this entity. Same as ``inherit_from_obligatory``. (*Deprecated*)
Usage Usage
===== =====
......
import unittest import unittest
from datetime import date from datetime import date
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from pytest import raises from pytest import deprecated_call, raises
import caosdb as db import caosdb as db
from caosadvancedtools.models.parser import (TwiceDefinedException, from caosadvancedtools.models.parser import (TwiceDefinedException,
...@@ -474,3 +474,40 @@ F: ...@@ -474,3 +474,40 @@ F:
""" """
with raises(NotImplementedError): with raises(NotImplementedError):
entities = parse_model_from_string(model) 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment