funcnodes-basic 0.1.9__py3-none-any.whl → 0.1.11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ from .strings import NODE_SHELF as strings_shelf
6
6
  from .dicts import NODE_SHELF as dicts_shelf
7
7
 
8
8
 
9
- __version__ = "0.1.9"
9
+ __version__ = "0.1.11"
10
10
 
11
11
  NODE_SHELF = Shelf(
12
12
  nodes=[],
funcnodes_basic/lists.py CHANGED
@@ -1,5 +1,6 @@
1
- from typing import List, Union, Any
1
+ from typing import List, Union, Any, Tuple
2
2
  import funcnodes_core as fn
3
+ import copy
3
4
 
4
5
 
5
6
  @fn.NodeDecorator(
@@ -10,56 +11,248 @@ def contains(collection: List[Union[str, Any]], item: Union[str, Any]) -> bool:
10
11
  return item in collection
11
12
 
12
13
 
13
- class GetIndexNode(fn.Node):
14
- node_id = "list.get"
15
- node_name = "Get Element"
16
- description = "Gets an element from a list."
17
- inputlist = fn.NodeInput(
18
- name="List",
19
- type=List[Union[str, Any]],
20
- uuid="inputlist",
21
- )
22
-
23
- index = fn.NodeInput(
24
- name="Index",
25
- type=int,
26
- uuid="index",
27
- )
28
-
29
- element = fn.NodeOutput(
30
- name="Element",
31
- type=Any,
32
- uuid="element",
33
- )
34
-
35
- def __init__(self, *args, **kwargs):
36
- super().__init__(*args, **kwargs)
37
- self.get_input("inputlist").on("after_set_value", self._update_indices)
38
-
39
- def _update_indices(self, **kwargs):
40
- try:
41
- lst = self.get_input("inputlist").value
42
- index = self.get_input("index")
43
- except KeyError:
44
- return
45
- try:
46
- index.update_value_options(min=0, max=len(lst) - 1)
47
- except Exception:
48
- index.update_value_options(min=0, max=0)
49
-
50
- async def func(
51
- self,
52
- inputlist: List[Any],
53
- index: int,
54
- ) -> Any:
55
- index = int(index)
56
- ele = inputlist[index]
57
- self.get_output("element").value = ele
58
- return ele
14
+ @fn.NodeDecorator(
15
+ id="list_get",
16
+ name="Get Element",
17
+ description="Gets an element from a list.",
18
+ default_io_options={
19
+ "lst": {
20
+ "on": {
21
+ "after_set_value": fn.decorator.update_other_io_value_options(
22
+ "index",
23
+ lambda result: {
24
+ "min": -len(result),
25
+ "max": len(result) - 1 if len(result) > 0 else 0,
26
+ },
27
+ )
28
+ }
29
+ },
30
+ },
31
+ outputs=[
32
+ {"name": "element"},
33
+ ],
34
+ )
35
+ def list_get(lst: List[Any], index: int = -1) -> Tuple[Any]:
36
+ # shallow copy the list
37
+ return lst[index]
38
+
39
+
40
+ @fn.NodeDecorator(
41
+ id="to_list",
42
+ name="To List",
43
+ )
44
+ def to_list(obj: Any) -> List[Any]:
45
+ try:
46
+ return list(obj)
47
+ except TypeError:
48
+ return [obj]
49
+
50
+
51
+ @fn.NodeDecorator(
52
+ id="list_length",
53
+ name="List Length",
54
+ )
55
+ def list_length(lst: List[Any]) -> int:
56
+ return len(lst)
57
+
58
+
59
+ @fn.NodeDecorator(
60
+ id="list_append",
61
+ name="List Append",
62
+ )
63
+ def list_append(lst: List[Any], item: Any) -> List[Any]:
64
+ return lst + [item]
65
+
66
+
67
+ @fn.NodeDecorator(
68
+ id="list_extend",
69
+ name="List Extend",
70
+ )
71
+ def list_extend(lst: List[Any], items: List[Any]) -> List[Any]:
72
+ return lst + items
73
+
74
+
75
+ @fn.NodeDecorator(
76
+ id="list_pop",
77
+ name="List Pop",
78
+ default_io_options={
79
+ "lst": {
80
+ "on": {
81
+ "after_set_value": fn.decorator.update_other_io_value_options(
82
+ "index",
83
+ lambda result: {
84
+ "min": -len(result),
85
+ "max": len(result) - 1 if len(result) > 0 else 0,
86
+ },
87
+ )
88
+ }
89
+ },
90
+ },
91
+ outputs=[
92
+ {"name": "new_list"},
93
+ {"name": "item"},
94
+ ],
95
+ )
96
+ def list_pop(lst: List[Any], index: int = -1) -> Tuple[List[Any], Any]:
97
+ # shallow copy the list
98
+ lst = copy.copy(lst)
99
+ item = lst.pop(index)
100
+ return lst, item
101
+
102
+
103
+ @fn.NodeDecorator(
104
+ id="list_remove",
105
+ name="List Remove",
106
+ )
107
+ def list_remove(lst: List[Any], item: Any, all: bool = False) -> List[Any]:
108
+ lst = copy.copy(lst)
109
+ if item in lst:
110
+ lst.remove(item)
111
+ if all:
112
+ while item in lst:
113
+ lst.remove(item)
114
+ return lst
115
+
116
+
117
+ @fn.NodeDecorator(
118
+ id="list_index",
119
+ name="List Index",
120
+ )
121
+ def list_index(lst: List[Any], item: Any) -> int:
122
+ return lst.index(item)
123
+
124
+
125
+ @fn.NodeDecorator(
126
+ id="list_reverse",
127
+ name="List Reverse",
128
+ )
129
+ def list_reverse(lst: List[Any]) -> List[Any]:
130
+ lst = copy.copy(lst)
131
+ lst.reverse()
132
+ return lst
133
+
134
+
135
+ @fn.NodeDecorator(
136
+ id="list_sort",
137
+ name="List Sort",
138
+ )
139
+ def list_sort(lst: List[Any], reverse: bool = False) -> List[Any]:
140
+ lst = copy.copy(lst)
141
+ lst.sort(reverse=reverse)
142
+ return lst
143
+
144
+
145
+ @fn.NodeDecorator(
146
+ id="list_count",
147
+ name="List Count",
148
+ )
149
+ def list_count(lst: List[Any], item: Any) -> int:
150
+ return lst.count(item)
151
+
152
+
153
+ @fn.NodeDecorator(
154
+ id="list_insert",
155
+ name="List Insert",
156
+ default_io_options={
157
+ "lst": {
158
+ "on": {
159
+ "after_set_value": fn.decorator.update_other_io_value_options(
160
+ "index",
161
+ lambda result: {
162
+ "min": -len(result),
163
+ "max": len(result),
164
+ },
165
+ )
166
+ }
167
+ },
168
+ },
169
+ )
170
+ def list_insert(lst: List[Any], item: Any, index: int = -1) -> List[Any]:
171
+ lst = copy.copy(lst)
172
+ lst.insert(index, item)
173
+ return lst
174
+
175
+
176
+ @fn.NodeDecorator(
177
+ id="list_set",
178
+ name="List Set",
179
+ default_io_options={
180
+ "lst": {
181
+ "on": {
182
+ "after_set_value": fn.decorator.update_other_io_value_options(
183
+ "index",
184
+ lambda result: {
185
+ "min": -len(result),
186
+ "max": len(result) - 1 if len(result) > 0 else 0,
187
+ },
188
+ )
189
+ }
190
+ },
191
+ },
192
+ )
193
+ def list_set(lst: List[Any], item: Any, index: int = -1) -> List[Any]:
194
+ lst = copy.copy(lst)
195
+ lst[index] = item
196
+ return lst
197
+
198
+
199
+ @fn.NodeDecorator(
200
+ id="list_slice",
201
+ name="List Slice",
202
+ default_io_options={
203
+ "lst": {
204
+ "on": {
205
+ "after_set_value": fn.decorator.update_other_io_value_options(
206
+ ["start", "end"],
207
+ lambda result: {"min": -len(result), "max": len(result) + 1},
208
+ ),
209
+ }
210
+ },
211
+ },
212
+ )
213
+ def list_slice(lst: List[Any], start: int = 0, end: int = -1) -> List[Any]:
214
+ return lst[start:end]
215
+
216
+
217
+ @fn.NodeDecorator(
218
+ id="list_slice_step",
219
+ name="List Slice Step",
220
+ default_io_options={
221
+ "lst": {
222
+ "on": {
223
+ "after_set_value": fn.decorator.update_other_io_value_options(
224
+ ["start", "end"],
225
+ lambda result: {"min": -len(result), "max": len(result) + 1},
226
+ ),
227
+ }
228
+ },
229
+ },
230
+ )
231
+ def list_slice_step(
232
+ lst: List[Any], start: int = 0, end: int = -1, step: int = 1
233
+ ) -> List[Any]:
234
+ return lst[start:end:step]
59
235
 
60
236
 
61
237
  NODE_SHELF = fn.Shelf(
62
- nodes=[contains, GetIndexNode],
238
+ nodes=[
239
+ contains,
240
+ list_get,
241
+ to_list,
242
+ list_length,
243
+ list_append,
244
+ list_extend,
245
+ list_pop,
246
+ list_remove,
247
+ list_index,
248
+ list_reverse,
249
+ list_sort,
250
+ list_count,
251
+ list_insert,
252
+ list_set,
253
+ list_slice,
254
+ list_slice_step,
255
+ ],
63
256
  subshelves=[],
64
257
  name="Lists",
65
258
  description="List operations",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcnodes-basic
3
- Version: 0.1.9
3
+ Version: 0.1.11
4
4
  Summary: Basic functionalities for funcnodes
5
5
  License: MIT
6
6
  Author: Julian Kimmig
@@ -10,8 +10,9 @@ Classifier: License :: OSI Approved :: MIT License
10
10
  Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
13
14
  Requires-Dist: funcnodes
14
- Requires-Dist: funcnodes-core (>=0.1.14)
15
+ Requires-Dist: funcnodes-core (>=0.1.24)
15
16
  Project-URL: download, https://pypi.org/project/funcnodes-basic/#files
16
17
  Project-URL: homepage, https://github.com/Linkdlab/funcnodes_basic
17
18
  Project-URL: source, https://github.com/Linkdlab/funcnodes_basic
@@ -0,0 +1,11 @@
1
+ funcnodes_basic/__init__.py,sha256=KuOmn4v9chfXk9dpxZGT_678bDZjfkpErOWrKjwB2fE,518
2
+ funcnodes_basic/dicts.py,sha256=koNJEwIq9ryC7evBpnI-QmR7MBIbgUWqpPpwhB3M69Y,2507
3
+ funcnodes_basic/lists.py,sha256=9kGnovK-oClFatslbIeYne27l2-EPEXZbr_6yQ1B1cY,5835
4
+ funcnodes_basic/logic.py,sha256=ecWXzkgjxYMfMdvm0Gdt-agsSbe9-_ilCNfhLz5OFXk,3575
5
+ funcnodes_basic/math_nodes.py,sha256=PasNf-1wAvbJ_c-_qeiIDaUVfgPQEREJApeUcTS4FQg,10586
6
+ funcnodes_basic/strings.py,sha256=O6rcxBQJ5eYd765w_tolaD6xMwsNmtBjiPgJ_69tKyA,16429
7
+ funcnodes_basic-0.1.11.dist-info/LICENSE,sha256=VcvnA4LohgMs8yTDTS1sS3aZbSFa3Ei9YeJogeosE7Y,1070
8
+ funcnodes_basic-0.1.11.dist-info/METADATA,sha256=Q85XfSoC8p8Jy48BJVq2rRBBRrvOtM5cmBr3_krokfs,2117
9
+ funcnodes_basic-0.1.11.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
10
+ funcnodes_basic-0.1.11.dist-info/entry_points.txt,sha256=Y7-9Rw_0qbyg8MrdLG6zjiEmUYBug_K4TBdJz9MAKxA,76
11
+ funcnodes_basic-0.1.11.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,11 +0,0 @@
1
- funcnodes_basic/__init__.py,sha256=36Udeh70dThxlUSkYl5mP48MUWEXZ8U3ylkuwjlXeJk,517
2
- funcnodes_basic/dicts.py,sha256=koNJEwIq9ryC7evBpnI-QmR7MBIbgUWqpPpwhB3M69Y,2507
3
- funcnodes_basic/lists.py,sha256=Sm4u1lqCbB9dQcY_YOTMRsBccUYfKGXaU_3kiqX8YhY,1566
4
- funcnodes_basic/logic.py,sha256=ecWXzkgjxYMfMdvm0Gdt-agsSbe9-_ilCNfhLz5OFXk,3575
5
- funcnodes_basic/math_nodes.py,sha256=PasNf-1wAvbJ_c-_qeiIDaUVfgPQEREJApeUcTS4FQg,10586
6
- funcnodes_basic/strings.py,sha256=O6rcxBQJ5eYd765w_tolaD6xMwsNmtBjiPgJ_69tKyA,16429
7
- funcnodes_basic-0.1.9.dist-info/LICENSE,sha256=VcvnA4LohgMs8yTDTS1sS3aZbSFa3Ei9YeJogeosE7Y,1070
8
- funcnodes_basic-0.1.9.dist-info/METADATA,sha256=a6_9yI530Wo1vEAG85AXsrrMmg0pU1YeNEKjHJXvJjU,2065
9
- funcnodes_basic-0.1.9.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
- funcnodes_basic-0.1.9.dist-info/entry_points.txt,sha256=Y7-9Rw_0qbyg8MrdLG6zjiEmUYBug_K4TBdJz9MAKxA,76
11
- funcnodes_basic-0.1.9.dist-info/RECORD,,