From 79faeb63a1ba8028517b965726d75b0bb68d7d27 Mon Sep 17 00:00:00 2001
From: Vincent Delbar <vincent.delbar@latelescop.fr>
Date: Sat, 5 Aug 2023 17:40:38 +0200
Subject: [PATCH 1/5] STYLE: summarize type hints #111

---
 pyotb/core.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/pyotb/core.py b/pyotb/core.py
index 71a032c..a39e0cf 100644
--- a/pyotb/core.py
+++ b/pyotb/core.py
@@ -1712,10 +1712,10 @@ def get_out_images_param_keys(app: OTBObject) -> list[str]:
 
 
 def summarize(
-    obj: App | Output | Any,
-    strip_input_paths: bool = False,
-    strip_output_paths: bool = False,
-) -> dict[str, str | dict[str, Any]]:
+    obj: App | Output | str | float | list,
+    strip_inpath: bool = False,
+    strip_outpath: bool = False,
+) -> dict[str, dict | Any] | str | float | list:
     """Recursively summarize parameters of an App or Output object and its parents.
 
     Args:
-- 
GitLab


From 2919258acb2062e1f81607376b5c5aa8c9fdd3b3 Mon Sep 17 00:00:00 2001
From: Vincent Delbar <vincent.delbar@latelescop.fr>
Date: Sat, 5 Aug 2023 17:41:06 +0200
Subject: [PATCH 2/5] DOC: better summarize() docstring

---
 pyotb/core.py | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/pyotb/core.py b/pyotb/core.py
index a39e0cf..acf72a1 100644
--- a/pyotb/core.py
+++ b/pyotb/core.py
@@ -1718,25 +1718,23 @@ def summarize(
 ) -> dict[str, dict | Any] | str | float | list:
     """Recursively summarize parameters of an App or Output object and its parents.
 
+    At the deepest recursion level, this function just return any parameter value,
+     path stripped if needed, or app summarized in case of a pipeline.
+
     Args:
-        obj: input object to summarize
-        strip_input_paths: strip all input paths: If enabled, paths related to
+        obj: input object / parameter value to summarize
+        strip_inpath: strip all input paths: If enabled, paths related to
             inputs are truncated after the first "?" character. Can be useful
             to remove URLs tokens (e.g. SAS or S3 credentials).
-        strip_output_paths: strip all output paths: If enabled, paths related
+        strip_outpath: strip all output paths: If enabled, paths related
             to outputs are truncated after the first "?" character. Can be
             useful to remove extended filenames.
 
     Returns:
-        nested dictionary with serialized App(s) containing name and parameters of an app and its parents
+        nested dictionary containing name and parameters of an app and its parents
 
     """
-
-    def strip_path(param: str | Any):
-        if not isinstance(param, str):
-            return summarize(param)
-        return param.split("?")[0]
-
+    # This is the deepest recursion level
     if isinstance(obj, list):
         return [summarize(o) for o in obj]
     if isinstance(obj, Output):
-- 
GitLab


From 39057f6ec3fff8d926d2ca19ed32b754658f1f79 Mon Sep 17 00:00:00 2001
From: Vincent Delbar <vincent.delbar@latelescop.fr>
Date: Sat, 5 Aug 2023 17:42:43 +0200
Subject: [PATCH 3/5] ENH: docstrings and readability of summarize(), shorter
 param names

---
 pyotb/core.py      | 1 +
 tests/test_core.py | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/pyotb/core.py b/pyotb/core.py
index acf72a1..54017d1 100644
--- a/pyotb/core.py
+++ b/pyotb/core.py
@@ -1742,6 +1742,7 @@ def summarize(
     if not isinstance(obj, App):
         return obj
 
+        if not isinstance(param, str):
     parameters = {}
     for key, param in obj.parameters.items():
         if (
diff --git a/tests/test_core.py b/tests/test_core.py
index 82173cd..d03f31f 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -348,9 +348,9 @@ def test_summarize_strip_output():
 
     baseline = [
         (in_fn, out_fn_w_ext, "out", {}, out_fn_w_ext),
-        (in_fn, out_fn_w_ext, "out", {"strip_output_paths": True}, out_fn),
+        (in_fn, out_fn_w_ext, "out", {"strip_outpath": True}, out_fn),
         (in_fn_w_ext, out_fn, "in", {}, in_fn_w_ext),
-        (in_fn_w_ext, out_fn, "in", {"strip_input_paths": True}, in_fn),
+        (in_fn_w_ext, out_fn, "in", {"strip_inpath": True}, in_fn),
     ]
 
     for inp, out, key, extra_args, expected in baseline:
-- 
GitLab


From 3753779ccdc74b0d0c8555d022bcafa7e3a8c747 Mon Sep 17 00:00:00 2001
From: Vincent Delbar <vincent.delbar@latelescop.fr>
Date: Sat, 5 Aug 2023 18:06:22 +0200
Subject: [PATCH 4/5] FIX: incomplete commit

---
 pyotb/core.py | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/pyotb/core.py b/pyotb/core.py
index 54017d1..ae6c13b 100644
--- a/pyotb/core.py
+++ b/pyotb/core.py
@@ -1742,20 +1742,19 @@ def summarize(
     if not isinstance(obj, App):
         return obj
 
+    # Call / top level of recursion : obj is an App
+    def strip_path(param: str | Any):
+        if isinstance(param, list):
+            return [strip_path(p) for p in param]
         if not isinstance(param, str):
+            return summarize(param)
+        return param.split("?")[0]
+
+    # We need to return parameters values, summarized if param is an App
     parameters = {}
     for key, param in obj.parameters.items():
-        if (
-            strip_input_paths
-            and obj.is_input(key)
-            or strip_output_paths
-            and obj.is_output(key)
-        ):
-            parameters[key] = (
-                [strip_path(p) for p in param]
-                if isinstance(param, list)
-                else strip_path(param)
-            )
+        if strip_inpath and obj.is_input(key) or strip_outpath and obj.is_output(key):
+            parameters[key] = strip_path(param)
         else:
             parameters[key] = summarize(param)
     return {"name": obj.app.GetName(), "parameters": parameters}
-- 
GitLab


From c67f1093ce7a1250c0107edc4c69ada78ddd1e4e Mon Sep 17 00:00:00 2001
From: Vincent Delbar <vincent.delbar@latelescop.fr>
Date: Sat, 5 Aug 2023 18:10:15 +0200
Subject: [PATCH 5/5] STYLE: move comment

---
 pyotb/core.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pyotb/core.py b/pyotb/core.py
index ae6c13b..76eef90 100644
--- a/pyotb/core.py
+++ b/pyotb/core.py
@@ -1742,7 +1742,6 @@ def summarize(
     if not isinstance(obj, App):
         return obj
 
-    # Call / top level of recursion : obj is an App
     def strip_path(param: str | Any):
         if isinstance(param, list):
             return [strip_path(p) for p in param]
@@ -1750,6 +1749,7 @@ def summarize(
             return summarize(param)
         return param.split("?")[0]
 
+    # Call / top level of recursion : obj is an App
     # We need to return parameters values, summarized if param is an App
     parameters = {}
     for key, param in obj.parameters.items():
-- 
GitLab