From 02a9f06a8c364a346ae0829f9dd1efc76dc1199a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi?= <remi.cresson@inrae.fr>
Date: Sat, 14 Dec 2024 13:36:32 +0100
Subject: [PATCH 1/3] bump version

---
 stac_extension_genmeta/__init__.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stac_extension_genmeta/__init__.py b/stac_extension_genmeta/__init__.py
index de41fca..da70881 100644
--- a/stac_extension_genmeta/__init__.py
+++ b/stac_extension_genmeta/__init__.py
@@ -1,2 +1,2 @@
 from .core import create_extension_cls
-__version__ = "0.0.24"
\ No newline at end of file
+__version__ = "0.1.0"
\ No newline at end of file
-- 
GitLab


From 2dfa9f9cdbb35cd0f9b54eabcc58568d38fd701d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi?= <remi.cresson@inrae.fr>
Date: Sat, 14 Dec 2024 13:36:53 +0100
Subject: [PATCH 2/3] implement kwargs passing in apply()

---
 stac_extension_genmeta/core.py | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/stac_extension_genmeta/core.py b/stac_extension_genmeta/core.py
index a2b994d..bcf66f3 100644
--- a/stac_extension_genmeta/core.py
+++ b/stac_extension_genmeta/core.py
@@ -67,10 +67,19 @@ def create_extension_cls(
             # forward getattr to self.md
             return getattr(self.md, item) if self.md else None
 
-        def apply(self, md: model_cls) -> None:
+        def apply(self, md: model_cls = None, **kwargs) -> None:
+
+            if md is None and not kwargs:
+                raise ValueError("At least `md` or kwargs is required")
+
+            if md and kwargs:
+                raise ValueError("You must use either `md` or kwargs")
+
+            if md and not isinstance(md, model_cls):
+                raise TypeError(f"`md` must be an instance of {model_cls}")
 
             # Set properties
-            dic = md.model_dump(exclude_unset=True)
+            dic = md.model_dump(exclude_unset=True) if md else kwargs
             for key, value in dic.items():
                 alias = model_cls.__fields__[key].alias or key
                 self._set_property(alias, value, pop_if_none=False)
-- 
GitLab


From e4a20203aac6ccb0aa15bbb92e7a6efa99a34fd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi?= <remi.cresson@inrae.fr>
Date: Sat, 14 Dec 2024 13:37:11 +0100
Subject: [PATCH 3/3] test kwargs passing in apply()

---
 stac_extension_genmeta/testing.py | 48 ++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 17 deletions(-)

diff --git a/stac_extension_genmeta/testing.py b/stac_extension_genmeta/testing.py
index 24ecd44..5f51e2d 100644
--- a/stac_extension_genmeta/testing.py
+++ b/stac_extension_genmeta/testing.py
@@ -53,6 +53,9 @@ def create_dummy_item(date=None):
     return item, col
 
 
+METHODS = ["arg", "md", "dict"]
+
+
 def basic_test(
         ext_md,
         ext_cls,
@@ -65,13 +68,23 @@ def basic_test(
         f"Extension metadata model: \n{ext_md.__class__.schema_json(indent=2)}"
     )
 
-    def apply(stac_obj):
+    def apply(stac_obj, method="arg"):
         """
         Apply the extension to the item
         """
         print(f"Check extension applied to {stac_obj.__class__.__name__}")
         ext = ext_cls.ext(stac_obj, add_if_missing=True)
-        ext.apply(ext_md)
+        if method == "arg":
+            ext.apply(ext_md)
+        elif method == "md":
+            ext.apply(md=ext_md)
+        elif method == "dict":
+            d = {
+                name: getattr(ext_md, name)
+                for name in ext_md.__fields__
+            }
+            print(f"Passing kwargs: {d}")
+            ext.apply(**d)
 
     def print_item(item):
         """
@@ -89,52 +102,53 @@ def basic_test(
             got = getattr(read_ext, field)
             assert got == ref, f"'{field}': values differ: {got} (expected {ref})"
 
-    def test_item():
+    def test_item(method):
         """
         Test extension against item
         """
         item, _ = create_dummy_item()
-        apply(item)
+        apply(item, method)
         print_item(item)
         if validate:
             item.validate()  # <--- This will try to read the actual schema URI
         # Check that we can retrieve the extension metadata from the item
         comp(item)
 
-    def test_asset():
+    def test_asset(method):
         """
         Test extension against asset
         """
         item, _ = create_dummy_item()
-        apply(item.assets["ndvi"])
+        apply(item.assets["ndvi"], method)
         print_item(item)
         if validate:
             item.validate()  # <--- This will try to read the actual schema URI
         # Check that we can retrieve the extension metadata from the asset
         comp(item.assets["ndvi"])
 
-    def test_collection():
+    def test_collection(method):
         """
         Test extension against collection
         """
         item, col = create_dummy_item()
         print_item(col)
-        apply(col)
+        apply(col, method)
         print_item(col)
         if validate:
             col.validate()  # <--- This will try to read the actual schema URI
         # Check that we can retrieve the extension metadata from the asset
         comp(col)
 
-    if item_test:
-        print("Test item")
-        test_item()
-    if asset_test:
-        print("Test asset")
-        test_asset()
-    if collection_test:
-        print("Test collection")
-        test_collection()
+    for method in METHODS:
+        if item_test:
+            print(f"Test item with {method} args passing strategy")
+            test_item(method)
+        if asset_test:
+            print(f"Test asset with {method} args passing strategy")
+            test_asset(method)
+        if collection_test:
+            print(f"Test collection with {method} args passing strategy")
+            test_collection(method)
 
 
 def is_schema_url_synced(cls):
-- 
GitLab