diff --git a/bindings/python/tests/input/test_ref_type_middle.yaml b/bindings/python/tests/input/test_ref_type_middle.yaml new file mode 100644 index 000000000..beaa596c5 --- /dev/null +++ b/bindings/python/tests/input/test_ref_type_middle.yaml @@ -0,0 +1,11 @@ +http://onto-ns.com/meta/0.2/Middle: + description: Middle-level nested data structure. + dimensions: [] + properties: + - name: name + type: string + description: Value of this structure. + - name: leaf + type: ref + $ref: http://onto-ns.com/meta/0.1/Leaf + description: Reference to low-level structure. diff --git a/bindings/python/tests/test_ref_type.py b/bindings/python/tests/test_ref_type.py index 5d7e62c5b..763198bf3 100644 --- a/bindings/python/tests/test_ref_type.py +++ b/bindings/python/tests/test_ref_type.py @@ -1,15 +1,24 @@ from pathlib import Path import dlite +from dlite.testutils import importcheck + +yaml = importcheck("yaml") thisdir = Path(__file__).resolve().parent indir = thisdir / "input" -dlite.storage_path.append(indir / "test_ref_type.json") +dlite.storage_path.append(indir) +dlite.storage_path.append(indir / "test_ref_type_middle.yaml") + +# If yaml is available, we read Middle v0.2, which is defined in +# `test_ref_type_middle.yaml`. Otherwise, we read Middle v0.1, which +# is defined together with the other datamodels in `test_ref_type.json`. +version = "0.2" if yaml else "0.1" Top = dlite.get_instance("http://onto-ns.com/meta/0.1/Top") -Middle = dlite.get_instance("http://onto-ns.com/meta/0.1/Middle") +Middle = dlite.get_instance(f"http://onto-ns.com/meta/{version}/Middle") Leaf = dlite.get_instance("http://onto-ns.com/meta/0.1/Leaf") Linked = dlite.get_instance("http://onto-ns.com/meta/0.1/Linked") Tree = dlite.get_instance("http://onto-ns.com/meta/0.1/Tree") @@ -78,6 +87,8 @@ assert cyclic.subtree[0].subtree[0] == cyclic assert cyclic.subtree[0].subtree[0].subtree[0] == cyclic -# Instantiate nested from dict -# For issue #515 -# middle = Middle(properties={"name": "nested", "leaf": {"a": 1, "b": True}}) +# For isue #982: ref-type in yaml +assert Middle.getprop("leaf").ref == "http://onto-ns.com/meta/0.1/Leaf" + +# For issue #515: Instantiate nested from dict +#middle = Middle(properties={"name": "nested", "leaf": {"a": 1, "b": True}}) diff --git a/bindings/python/utils.py b/bindings/python/utils.py index 6f7047f7a..87eebc359 100644 --- a/bindings/python/utils.py +++ b/bindings/python/utils.py @@ -136,8 +136,16 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): if meta.is_metameta: if "uri" in d: uri = d["uri"] - else: + elif "identity" in d: + uri = d["identity"] + elif "name" in d and "version" in d and "namespace" in d: uri = dlite.join_meta_uri(d["name"], d["version"], d["namespace"]) + elif id and dlite.urlparse(id).scheme: + uri = id + else: + raise TypeError( + "`id` required for metadata when the URI is not in the dict" + ) if check_storages: try: @@ -169,6 +177,7 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): dlite.Property( name=p["name"], type=p["type"], + ref=p.get("$ref", p.get("ref")), shape=p.get("shape", p.get("dims")), unit=p.get("unit"), description=p.get("description"), @@ -180,6 +189,7 @@ def instance_from_dict(d, id=None, single=None, check_storages=True): dlite.Property( name=k, type=v["type"], + ref=v.get("$ref", v.get("ref")), shape=v.get("shape", v.get("dims")), unit=v.get("unit"), description=v.get("description"), diff --git a/python/setup.py b/python/setup.py index 00a3f6cbd..91e04c267 100644 --- a/python/setup.py +++ b/python/setup.py @@ -202,7 +202,6 @@ def run(self): "Operating System :: POSIX :: Linux", "Operating System :: Microsoft :: Windows", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", diff --git a/requirements_full.txt b/requirements_full.txt index 7899f2803..a448265d6 100644 --- a/requirements_full.txt +++ b/requirements_full.txt @@ -13,7 +13,7 @@ pyarrow>=14.0,<18.0 tables>=3.8,<5.0 openpyxl>=3.0.9,<3.2 jinja2>=3.0,<4 -paramiko>=3.0.0,<3.4.1 +paramiko>=3.0.0,<3.5.1 requests>=2.10,<3 redis>=5.0,<6 minio>=6.0,<8