From 384af3a2b432a6676b4dc2e88c915c3149acc8cc Mon Sep 17 00:00:00 2001 From: Shiki <64834708+xshiki@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:05:08 +0100 Subject: [PATCH 1/8] Added set support for arrays --- ipywidgets_jsonschema/form.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ipywidgets_jsonschema/form.py b/ipywidgets_jsonschema/form.py index fdf4a9f..9d2de37 100644 --- a/ipywidgets_jsonschema/form.py +++ b/ipywidgets_jsonschema/form.py @@ -931,12 +931,19 @@ def _resetter(): # Initially call the resetter _resetter() + def _getter(): + result = [h.getter() for h in elements[:element_size]] + if schema.get("set", False): + if len(result) != len(set(result)): + raise FormError("Array elements are not unique") + return result + wrapped_vbox[0] = self._wrap_description( wrapped_vbox[0], schema.get("description", None) ) return self.construct_element( - getter=lambda: [h.getter() for h in elements[:element_size]], + getter=_getter, setter=_setter, resetter=_resetter, widgets=wrapped_vbox, From 133d544d1ad24e5e35784654338904e57faf4336 Mon Sep 17 00:00:00 2001 From: Shiki <64834708+xshiki@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:46:24 +0100 Subject: [PATCH 2/8] Added test case for array set --- .DS_Store | Bin 0 -> 8196 bytes ipywidgets_jsonschema/.DS_Store | Bin 0 -> 6148 bytes tests/schemas/array-set.json | 30 ++++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 .DS_Store create mode 100644 ipywidgets_jsonschema/.DS_Store create mode 100644 tests/schemas/array-set.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..e5036e878bf2f29f4d3e4a0d0a8ecbc563bcf9f9 GIT binary patch literal 8196 zcmeHMU2GIp6h3EK=$$D)Q*5DAT)J98C$)a|BjqHK`~fU5U<6F?!Mn~n z8i){x5Qq?n5Qq?n5V#o-pfj5{HpRIwW}`krAVT1Oi2≈&gGD2<5nt!PY@tPy&$T zB|y;Vp6YC(NP-eZ}?lv>^8I=*f> zW-f5B43kXu4_c1l7CYU%V|amYQcTD)lT&K#i4$vD+M42PR=1vPil5lf(%ckp-OzIK zq|9m>R<-X+9kIt8_el{Xh8qRUo)q*`(~H>l3SA=Nvbs{l--Hn}S*g?phm_%zI%foxyvLwt6+AMwKrtZa@?$XQdlUTomCUNbIJ1NwvG37_w9J#((E~N zRb`%1Jy@_jD{Y&*i8yeA*=7R{RX|@4%gr-8o`WKuPtV5A0O|^nbeD6WvSLEt2!I- zC=Rj23T2h7dh);#B7kshQCgX5$h&PlZQ5dJow9+c+vLH5z*h`zQto9{*dz~S+_5o= z#}mUHS{GB#vxEHE+jY5~iMt6wq38WN4-3k9&s4T+)V6h4km;AwmTU&NR2WqcFQ;@fx* z-@(uDbNm9o#EWrDam1v|MVE+N6zAyLfl0lvDdAl27U; zeHyz655P*<*sDQX!dn;iJAX(SaxW!-v3QOhaq#N4KPNCmzV2)(0|R^mzY56FBDK7vo- z0$d_8{{%n7uW*$JJO`_Zyi0H?5x5Cg5P{d@Mr_ATxEXt~54RGX2XGG#;a(iZ44OEC zqi7MCeavG4AI3+B(2o(NPvbNAEIx*x^*H|@#E=HwUEp? zw(E?LSBd-+7rceFGV$)Uy#C)j_3!_;aD>sTM+ig+{2c;V-kt33B&(@*I9_YV={iIg yZ`^KN$iRgH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 13 Jan 2025 16:05:40 +0100 Subject: [PATCH 3/8] Update array-set.json --- tests/schemas/array-set.json | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/schemas/array-set.json b/tests/schemas/array-set.json index ff89dcd..0a4feb7 100644 --- a/tests/schemas/array-set.json +++ b/tests/schemas/array-set.json @@ -7,6 +7,7 @@ "type": "string" }, "uniqueItems": true, + "set": true, "type": "array" }, "valid": [ From d10dae0a24ecf2134d5a27ea845124d4c4fca758 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 15:05:56 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/schemas/array-set.json | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/tests/schemas/array-set.json b/tests/schemas/array-set.json index 0a4feb7..91e1cd5 100644 --- a/tests/schemas/array-set.json +++ b/tests/schemas/array-set.json @@ -1,14 +1,21 @@ { "default": [], + "invalid": [ + [ + "1", + "1", + "3" + ] + ], "schema": { "description": "Bla bla", "items": { "default": "foo", "type": "string" }, - "uniqueItems": true, "set": true, - "type": "array" + "type": "array", + "uniqueItems": true }, "valid": [ [ @@ -19,13 +26,5 @@ "2", "3" ] - ], - "invalid": [ - [ - "1", - "1", - "3" - ] ] } - From e26de260f96208d505db5b555d9e0531f52eaa88 Mon Sep 17 00:00:00 2001 From: Shiki <64834708+xshiki@users.noreply.github.com> Date: Fri, 17 Jan 2025 18:11:47 +0100 Subject: [PATCH 5/8] Removed .DS_Store files --- .DS_Store | Bin 8196 -> 0 bytes ipywidgets_jsonschema/.DS_Store | Bin 6148 -> 0 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store delete mode 100644 ipywidgets_jsonschema/.DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index e5036e878bf2f29f4d3e4a0d0a8ecbc563bcf9f9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8196 zcmeHMU2GIp6h3EK=$$D)Q*5DAT)J98C$)a|BjqHK`~fU5U<6F?!Mn~n z8i){x5Qq?n5Qq?n5V#o-pfj5{HpRIwW}`krAVT1Oi2≈&gGD2<5nt!PY@tPy&$T zB|y;Vp6YC(NP-eZ}?lv>^8I=*f> zW-f5B43kXu4_c1l7CYU%V|amYQcTD)lT&K#i4$vD+M42PR=1vPil5lf(%ckp-OzIK zq|9m>R<-X+9kIt8_el{Xh8qRUo)q*`(~H>l3SA=Nvbs{l--Hn}S*g?phm_%zI%foxyvLwt6+AMwKrtZa@?$XQdlUTomCUNbIJ1NwvG37_w9J#((E~N zRb`%1Jy@_jD{Y&*i8yeA*=7R{RX|@4%gr-8o`WKuPtV5A0O|^nbeD6WvSLEt2!I- zC=Rj23T2h7dh);#B7kshQCgX5$h&PlZQ5dJow9+c+vLH5z*h`zQto9{*dz~S+_5o= z#}mUHS{GB#vxEHE+jY5~iMt6wq38WN4-3k9&s4T+)V6h4km;AwmTU&NR2WqcFQ;@fx* z-@(uDbNm9o#EWrDam1v|MVE+N6zAyLfl0lvDdAl27U; zeHyz655P*<*sDQX!dn;iJAX(SaxW!-v3QOhaq#N4KPNCmzV2)(0|R^mzY56FBDK7vo- z0$d_8{{%n7uW*$JJO`_Zyi0H?5x5Cg5P{d@Mr_ATxEXt~54RGX2XGG#;a(iZ44OEC zqi7MCeavG4AI3+B(2o(NPvbNAEIx*x^*H|@#E=HwUEp? zw(E?LSBd-+7rceFGV$)Uy#C)j_3!_;aD>sTM+ig+{2c;V-kt33B&(@*I9_YV={iIg yZ`^KN$iRgH1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 20 Jan 2025 20:52:45 +0100 Subject: [PATCH 6/8] Changed logic for sets Converts array to set if either "set" or "uniqueItems" key is present in schema --- ipywidgets_jsonschema/form.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ipywidgets_jsonschema/form.py b/ipywidgets_jsonschema/form.py index 9d2de37..a460b47 100644 --- a/ipywidgets_jsonschema/form.py +++ b/ipywidgets_jsonschema/form.py @@ -933,9 +933,8 @@ def _resetter(): def _getter(): result = [h.getter() for h in elements[:element_size]] - if schema.get("set", False): - if len(result) != len(set(result)): - raise FormError("Array elements are not unique") + if any(key.lower() in {"set", "uniqueitems"} and schema.get(key, False) for key in schema): + result = list(set(result)) return result wrapped_vbox[0] = self._wrap_description( From a2d97cdc84463f6f0388f3d9e9ebb2cb30ef533f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:53:10 +0000 Subject: [PATCH 7/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ipywidgets_jsonschema/form.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ipywidgets_jsonschema/form.py b/ipywidgets_jsonschema/form.py index a460b47..25fdc0a 100644 --- a/ipywidgets_jsonschema/form.py +++ b/ipywidgets_jsonschema/form.py @@ -933,7 +933,10 @@ def _resetter(): def _getter(): result = [h.getter() for h in elements[:element_size]] - if any(key.lower() in {"set", "uniqueitems"} and schema.get(key, False) for key in schema): + if any( + key.lower() in {"set", "uniqueitems"} and schema.get(key, False) + for key in schema + ): result = list(set(result)) return result From 47b47c392fd967a51fffc75fb34a421bd11e772a Mon Sep 17 00:00:00 2001 From: Shiki <64834708+xshiki@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:45:06 +0100 Subject: [PATCH 8/8] Removed "set" key --- ipywidgets_jsonschema/form.py | 5 +---- tests/schemas/array-set.json | 1 - 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/ipywidgets_jsonschema/form.py b/ipywidgets_jsonschema/form.py index 25fdc0a..7824625 100644 --- a/ipywidgets_jsonschema/form.py +++ b/ipywidgets_jsonschema/form.py @@ -933,10 +933,7 @@ def _resetter(): def _getter(): result = [h.getter() for h in elements[:element_size]] - if any( - key.lower() in {"set", "uniqueitems"} and schema.get(key, False) - for key in schema - ): + if schema.get("uniqueItems", False): result = list(set(result)) return result diff --git a/tests/schemas/array-set.json b/tests/schemas/array-set.json index 91e1cd5..676361d 100644 --- a/tests/schemas/array-set.json +++ b/tests/schemas/array-set.json @@ -13,7 +13,6 @@ "default": "foo", "type": "string" }, - "set": true, "type": "array", "uniqueItems": true },