From 17d42b469ae0774a2832debd0a1f7b2f0b420f35 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 20 Nov 2024 21:17:45 -0500 Subject: [PATCH 1/5] repeat_dict for sphinx --- docs/nb.ipynb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/nb.ipynb b/docs/nb.ipynb index 9350ffd..8be732c 100644 --- a/docs/nb.ipynb +++ b/docs/nb.ipynb @@ -29,10 +29,14 @@ " 3\n", " ],\n", " \"test_variant\": \"test_variant_argument\",\n", - " \"test_repeat\": [\n", + " \"test_repeat_list\": [\n", " {\"test_repeat_item\": false},\n", " {\"test_repeat_item\": true}\n", " ],\n", + " \"test_repeat_dict\": [\n", + " \"test1\": {\"test_repeat_item\": false},\n", + " \"test2\": {\"test_repeat_item\": true}\n", + " ],\n", " \"_comment\": \"This is an example data\"\n", "}\n", "\"\"\"\n", From 61bea6c94acb07b13ff9047181e60d108d0f4c9a Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 20 Nov 2024 21:19:56 -0500 Subject: [PATCH 2/5] Fix JSON structure in nb.ipynb --- docs/nb.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/nb.ipynb b/docs/nb.ipynb index 8be732c..816d94f 100644 --- a/docs/nb.ipynb +++ b/docs/nb.ipynb @@ -33,10 +33,10 @@ " {\"test_repeat_item\": false},\n", " {\"test_repeat_item\": true}\n", " ],\n", - " \"test_repeat_dict\": [\n", + " \"test_repeat_dict\": {\n", " \"test1\": {\"test_repeat_item\": false},\n", " \"test2\": {\"test_repeat_item\": true}\n", - " ],\n", + " },\n", " \"_comment\": \"This is an example data\"\n", "}\n", "\"\"\"\n", From 52cc61cff4565104488fbd2894fd8159965670b6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 20 Nov 2024 21:30:16 -0500 Subject: [PATCH 3/5] Add condition to check `arg.repeat` in `_init_subdata` --- dargs/notebook.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index c60c366..3904bda 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -157,7 +157,7 @@ def __init__(self, data: dict, arg: Argument | Variant): def _init_subdata(self): """Initialize sub ArgumentData.""" - if isinstance(self.data, dict) and isinstance(self.arg, Argument): + if isinstance(self.data, dict) and isinstance(self.arg, Argument) and not self.arg.repeat: sub_fields = self.arg.sub_fields.copy() # extend subfiles with sub_variants for vv in self.arg.sub_variants.values(): @@ -175,7 +175,7 @@ def _init_subdata(self): else: self.subdata.append(ArgumentData(self.data[kk], kk)) elif ( - isinstance(self.data, list) + isinstance(self.data, (list, dict)) and isinstance(self.arg, Argument) and self.arg.repeat ): From 3cf24449cd9d251fc4d399d0a6dd197dfd7aefe2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 21 Nov 2024 02:30:22 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dargs/notebook.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index 3904bda..bc3e89c 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -157,7 +157,11 @@ def __init__(self, data: dict, arg: Argument | Variant): def _init_subdata(self): """Initialize sub ArgumentData.""" - if isinstance(self.data, dict) and isinstance(self.arg, Argument) and not self.arg.repeat: + if ( + isinstance(self.data, dict) + and isinstance(self.arg, Argument) + and not self.arg.repeat + ): sub_fields = self.arg.sub_fields.copy() # extend subfiles with sub_variants for vv in self.arg.sub_variants.values(): From 153d668576585f3448243b1d2a179ec508b840d2 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Wed, 20 Nov 2024 22:09:38 -0500 Subject: [PATCH 5/5] fixed Signed-off-by: Jinzhe Zeng --- dargs/notebook.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dargs/notebook.py b/dargs/notebook.py index bc3e89c..9d1849f 100644 --- a/dargs/notebook.py +++ b/dargs/notebook.py @@ -147,11 +147,14 @@ class ArgumentData: The data to be displayed. arg : Union[dargs.Argument, dargs.Variant] The Argument that describes the data. + repeat : bool, optional + The argument is repeat """ - def __init__(self, data: dict, arg: Argument | Variant): + def __init__(self, data: dict, arg: Argument | Variant, repeat: bool = False): self.data = data self.arg = arg + self.repeat = repeat self.subdata = [] self._init_subdata() @@ -160,7 +163,7 @@ def _init_subdata(self): if ( isinstance(self.data, dict) and isinstance(self.arg, Argument) - and not self.arg.repeat + and not (self.arg.repeat and not self.repeat) ): sub_fields = self.arg.sub_fields.copy() # extend subfiles with sub_variants @@ -179,12 +182,21 @@ def _init_subdata(self): else: self.subdata.append(ArgumentData(self.data[kk], kk)) elif ( - isinstance(self.data, (list, dict)) + isinstance(self.data, list) and isinstance(self.arg, Argument) and self.arg.repeat + and not self.repeat ): for dd in self.data: - self.subdata.append(ArgumentData(dd, self.arg)) + self.subdata.append(ArgumentData(dd, self.arg, repeat=True)) + elif ( + isinstance(self.data, dict) + and isinstance(self.arg, Argument) + and self.arg.repeat + and not self.repeat + ): + for dd in self.data.values(): + self.subdata.append(ArgumentData(dd, self.arg, repeat=True)) def print_html(self, _level=0, _last_one=True): """Print the data with Argument in HTML format. @@ -207,7 +219,7 @@ def print_html(self, _level=0, _last_one=True): if _level > 0 and not ( isinstance(self.data, dict) and isinstance(self.arg, Argument) - and self.arg.repeat + and self.repeat ): if isinstance(self.arg, (Argument, Variant)): buff.append(r"""""")