funcnodes-basic 0.1.8__tar.gz → 0.1.10__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: funcnodes-basic
3
- Version: 0.1.8
3
+ Version: 0.1.10
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
@@ -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.8"
9
+ __version__ = "0.1.10"
10
10
 
11
11
  NODE_SHELF = Shelf(
12
12
  nodes=[],
@@ -0,0 +1,272 @@
1
+ from typing import List, Union, Any, Tuple
2
+ import funcnodes_core as fn
3
+ import copy
4
+
5
+
6
+ @fn.NodeDecorator(
7
+ id="contains_node",
8
+ name="Contains",
9
+ )
10
+ def contains(collection: List[Union[str, Any]], item: Union[str, Any]) -> bool:
11
+ return item in collection
12
+
13
+
14
+ class GetIndexNode(fn.Node):
15
+ node_id = "list.get"
16
+ node_name = "Get Element"
17
+ description = "Gets an element from a list."
18
+ inputlist = fn.NodeInput(
19
+ name="List",
20
+ type=List[Union[str, Any]],
21
+ uuid="inputlist",
22
+ )
23
+
24
+ index = fn.NodeInput(
25
+ name="Index",
26
+ type=int,
27
+ uuid="index",
28
+ )
29
+
30
+ element = fn.NodeOutput(
31
+ name="Element",
32
+ type=Any,
33
+ uuid="element",
34
+ )
35
+
36
+ def __init__(self, *args, **kwargs):
37
+ super().__init__(*args, **kwargs)
38
+ self.get_input("inputlist").on("after_set_value", self._update_indices)
39
+
40
+ def _update_indices(self, **kwargs):
41
+ try:
42
+ lst = self.get_input("inputlist").value
43
+ index = self.get_input("index")
44
+ except KeyError:
45
+ return
46
+ try:
47
+ index.update_value_options(min=0, max=len(lst) - 1)
48
+ except Exception:
49
+ index.update_value_options(min=0, max=0)
50
+
51
+ async def func(
52
+ self,
53
+ inputlist: List[Any],
54
+ index: int,
55
+ ) -> Any:
56
+ index = int(index)
57
+ ele = inputlist[index]
58
+ self.get_output("element").value = ele
59
+ return ele
60
+
61
+
62
+ @fn.NodeDecorator(
63
+ id="to_list",
64
+ name="To List",
65
+ )
66
+ def to_list(obj: Any) -> List[Any]:
67
+ try:
68
+ return list(obj)
69
+ except TypeError:
70
+ return [obj]
71
+
72
+
73
+ @fn.NodeDecorator(
74
+ id="list_length",
75
+ name="List Length",
76
+ )
77
+ def list_length(lst: List[Any]) -> int:
78
+ return len(lst)
79
+
80
+
81
+ @fn.NodeDecorator(
82
+ id="list_append",
83
+ name="List Append",
84
+ )
85
+ def list_append(lst: List[Any], item: Any) -> List[Any]:
86
+ return lst + [item]
87
+
88
+
89
+ @fn.NodeDecorator(
90
+ id="list_extend",
91
+ name="List Extend",
92
+ )
93
+ def list_extend(lst: List[Any], items: List[Any]) -> List[Any]:
94
+ return lst + items
95
+
96
+
97
+ @fn.NodeDecorator(
98
+ id="list_pop",
99
+ name="List Pop",
100
+ default_io_options={
101
+ "lst": {
102
+ "on": {
103
+ "after_set_value": fn.decorator.update_other_io_value_options(
104
+ "index",
105
+ lambda result: {"min": 0, "max": len(result) - 1},
106
+ )
107
+ }
108
+ },
109
+ },
110
+ outputs=[
111
+ {"name": "new_list"},
112
+ {"name": "item"},
113
+ ],
114
+ )
115
+ def list_pop(lst: List[Any], index: int) -> Tuple[List[Any], Any]:
116
+ # shallow copy the list
117
+ lst = copy.copy(lst)
118
+ item = lst.pop(index)
119
+ return lst, item
120
+
121
+
122
+ @fn.NodeDecorator(
123
+ id="list_remove",
124
+ name="List Remove",
125
+ )
126
+ def list_remove(lst: List[Any], item: Any, all: bool = False) -> List[Any]:
127
+ lst = copy.copy(lst)
128
+ if item in lst:
129
+ lst.remove(item)
130
+ if all:
131
+ while item in lst:
132
+ lst.remove(item)
133
+ return lst
134
+
135
+
136
+ @fn.NodeDecorator(
137
+ id="list_index",
138
+ name="List Index",
139
+ )
140
+ def list_index(lst: List[Any], item: Any) -> int:
141
+ return lst.index(item)
142
+
143
+
144
+ @fn.NodeDecorator(
145
+ id="list_reverse",
146
+ name="List Reverse",
147
+ )
148
+ def list_reverse(lst: List[Any]) -> List[Any]:
149
+ lst = copy.copy(lst)
150
+ lst.reverse()
151
+ return lst
152
+
153
+
154
+ @fn.NodeDecorator(
155
+ id="list_sort",
156
+ name="List Sort",
157
+ )
158
+ def list_sort(lst: List[Any], reverse: bool = False) -> List[Any]:
159
+ lst = copy.copy(lst)
160
+ lst.sort(reverse=reverse)
161
+ return lst
162
+
163
+
164
+ @fn.NodeDecorator(
165
+ id="list_count",
166
+ name="List Count",
167
+ )
168
+ def list_count(lst: List[Any], item: Any) -> int:
169
+ return lst.count(item)
170
+
171
+
172
+ @fn.NodeDecorator(
173
+ id="list_insert",
174
+ name="List Insert",
175
+ default_io_options={
176
+ "lst": {
177
+ "on": {
178
+ "after_set_value": fn.decorator.update_other_io_value_options(
179
+ "index",
180
+ lambda result: {"min": 0, "max": len(result)},
181
+ )
182
+ }
183
+ },
184
+ },
185
+ )
186
+ def list_insert(lst: List[Any], index: int, item: Any) -> List[Any]:
187
+ lst = copy.copy(lst)
188
+ lst.insert(index, item)
189
+ return lst
190
+
191
+
192
+ @fn.NodeDecorator(
193
+ id="list_set",
194
+ name="List Set",
195
+ default_io_options={
196
+ "lst": {
197
+ "on": {
198
+ "after_set_value": fn.decorator.update_other_io_value_options(
199
+ "index",
200
+ lambda result: {"min": 0, "max": len(result) - 1},
201
+ )
202
+ }
203
+ },
204
+ },
205
+ )
206
+ def list_set(lst: List[Any], index: int, item: Any) -> List[Any]:
207
+ lst = copy.copy(lst)
208
+ lst[index] = item
209
+ return lst
210
+
211
+
212
+ @fn.NodeDecorator(
213
+ id="list_slice",
214
+ name="List Slice",
215
+ default_io_options={
216
+ "lst": {
217
+ "on": {
218
+ "after_set_value": fn.decorator.update_other_io_value_options(
219
+ ["start", "end"],
220
+ lambda result: {"min": -len(result), "max": len(result) + 1},
221
+ ),
222
+ }
223
+ },
224
+ },
225
+ )
226
+ def list_slice(lst: List[Any], start: int = 0, end: int = -1) -> List[Any]:
227
+ return lst[start:end]
228
+
229
+
230
+ @fn.NodeDecorator(
231
+ id="list_slice_step",
232
+ name="List Slice Step",
233
+ default_io_options={
234
+ "lst": {
235
+ "on": {
236
+ "after_set_value": fn.decorator.update_other_io_value_options(
237
+ ["start", "end"],
238
+ lambda result: {"min": -len(result), "max": len(result) + 1},
239
+ ),
240
+ }
241
+ },
242
+ },
243
+ )
244
+ def list_slice_step(
245
+ lst: List[Any], start: int = 0, end: int = -1, step: int = 1
246
+ ) -> List[Any]:
247
+ return lst[start:end:step]
248
+
249
+
250
+ NODE_SHELF = fn.Shelf(
251
+ nodes=[
252
+ contains,
253
+ GetIndexNode,
254
+ to_list,
255
+ list_length,
256
+ list_append,
257
+ list_extend,
258
+ list_pop,
259
+ list_remove,
260
+ list_index,
261
+ list_reverse,
262
+ list_sort,
263
+ list_count,
264
+ list_insert,
265
+ list_set,
266
+ list_slice,
267
+ list_slice_step,
268
+ ],
269
+ subshelves=[],
270
+ name="Lists",
271
+ description="List operations",
272
+ )
@@ -22,9 +22,7 @@ def value_node(value: float) -> float:
22
22
  )
23
23
  def add_node(a: float, b: float) -> float:
24
24
  """Add two numbers"""
25
- a = float(a)
26
- b = float(b)
27
- return a + b
25
+ return float(a) + float(b)
28
26
 
29
27
 
30
28
  @NodeDecorator(
@@ -154,7 +154,7 @@ def string_split(s: str, delimiter: Optional[str] = None) -> List[str]:
154
154
  {"name": "joined"},
155
155
  ],
156
156
  )
157
- def string_join(strings: List[str], delimiter: str = " ") -> str:
157
+ def string_join(strings: List[str], delimiter: str = "") -> str:
158
158
  return delimiter.join(strings)
159
159
 
160
160
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "funcnodes-basic"
3
- version = "0.1.8"
3
+ version = "0.1.10"
4
4
  description = "Basic functionalities for funcnodes"
5
5
  authors = ["Julian Kimmig <julian.kimmig@gmx.net>"]
6
6
  readme = "README.md"
@@ -15,7 +15,7 @@ download = "https://pypi.org/project/funcnodes-basic/#files"
15
15
 
16
16
  [tool.poetry.dependencies]
17
17
  python = ">=3.11"
18
- funcnodes-core = ">=0.1.14"
18
+ funcnodes-core = ">=0.1.24"
19
19
  funcnodes = "*"
20
20
 
21
21
  [tool.poetry.group.dev.dependencies]
@@ -1,66 +0,0 @@
1
- from typing import List, Union, Any
2
- import funcnodes_core as fn
3
-
4
-
5
- @fn.NodeDecorator(
6
- id="contains_node",
7
- name="Contains",
8
- )
9
- def contains(collection: List[Union[str, Any]], item: Union[str, Any]) -> bool:
10
- return item in collection
11
-
12
-
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
59
-
60
-
61
- NODE_SHELF = fn.Shelf(
62
- nodes=[contains, GetIndexNode],
63
- subshelves=[],
64
- name="Lists",
65
- description="List operations",
66
- )