funcnodes-basic 0.2.2__py3-none-any.whl → 0.2.4__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.
@@ -5,9 +5,9 @@ from .lists import NODE_SHELF as lists_shelf
5
5
  from .strings import NODE_SHELF as strings_shelf
6
6
  from .dicts import NODE_SHELF as dicts_shelf
7
7
  from .input import NODE_SHELF as input_shelf
8
+ from .dataclass import NODE_SHELF as dataclass_shelf
8
9
 
9
-
10
- __version__ = "0.2.2"
10
+ __version__ = "0.2.3"
11
11
 
12
12
  NODE_SHELF = Shelf(
13
13
  nodes=[],
@@ -15,6 +15,7 @@ NODE_SHELF = Shelf(
15
15
  input_shelf,
16
16
  lists_shelf,
17
17
  dicts_shelf,
18
+ dataclass_shelf,
18
19
  strings_shelf,
19
20
  math_shelf,
20
21
  logic_shelf,
@@ -0,0 +1,64 @@
1
+ import dataclasses
2
+ import funcnodes_core as fn
3
+ from typing import Any, Dict
4
+
5
+
6
+ @fn.NodeDecorator(
7
+ id="dataclass.to_dict",
8
+ )
9
+ def dataclass_to_dict(instance: Any) -> Dict[str, Any]:
10
+ """
11
+ Convert a dataclass instance to a dictionary.
12
+
13
+ Args:
14
+ instance (object): The dataclass instance to convert.
15
+
16
+ Returns:
17
+ dict: The dictionary representation of the dataclass instance.
18
+ """
19
+ if not dataclasses.is_dataclass(instance):
20
+ raise TypeError(f"Expected a dataclass instance, got {type(instance)}")
21
+
22
+ return dataclasses.asdict(instance)
23
+
24
+
25
+ @fn.NodeDecorator(
26
+ id="dataclass.get_field",
27
+ default_io_options={
28
+ "instance": {
29
+ "on": {
30
+ "after_set_value": fn.decorator.update_other_io_value_options(
31
+ "field_name",
32
+ lambda result: {
33
+ "options": [field.name for field in dataclasses.fields(result)]
34
+ if dataclasses.is_dataclass(result)
35
+ else None,
36
+ },
37
+ )
38
+ }
39
+ }
40
+ },
41
+ )
42
+ def dataclass_get_field(instance: Any, field_name: str) -> Any:
43
+ """
44
+ Get a field value from a dataclass instance.
45
+ """
46
+ if not dataclasses.is_dataclass(instance):
47
+ raise TypeError(f"Expected a dataclass instance, got {type(instance)}")
48
+
49
+ if not hasattr(instance, field_name):
50
+ raise AttributeError(
51
+ f"{instance.__class__.__name__} has no field '{field_name}'"
52
+ )
53
+
54
+ return getattr(instance, field_name)
55
+
56
+
57
+ NODE_SHELF = fn.Shelf(
58
+ nodes=[
59
+ dataclass_to_dict,
60
+ dataclass_get_field,
61
+ ],
62
+ name="dataclass",
63
+ description="Nodes for working with dataclasses",
64
+ )
funcnodes_basic/logic.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Logic Nodes for control flow and decision making."""
2
2
 
3
- from funcnodes_core.node import Node, TriggerStack
3
+ from funcnodes_core.node import Node
4
4
  from typing import Any, List, Optional
5
5
  from funcnodes_core.io import NodeInput, NodeOutput, NoValue
6
6
  import asyncio
@@ -35,8 +35,19 @@ class WhileNode(Node):
35
35
  async def func(self, condition: bool, input: Any) -> None:
36
36
  if self.inputs["condition"].value:
37
37
  self.outputs["do"].value = input
38
- triggerstack = TriggerStack()
39
- await self.outputs["do"].trigger(triggerstack)
38
+ datapaths = [
39
+ ip.datapath
40
+ for ip in self.outputs["do"].connections
41
+ if ip.datapath is not None
42
+ ]
43
+
44
+ while datapaths:
45
+ for dp in datapaths:
46
+ if dp.done(breaking_nodes=[self]):
47
+ datapaths.remove(dp)
48
+ break
49
+ else:
50
+ await asyncio.sleep(0.1)
40
51
  self.request_trigger()
41
52
  else:
42
53
  self.outputs["done"].value = input
@@ -94,9 +105,21 @@ class ForNode(Node):
94
105
  pass
95
106
 
96
107
  for i in self.progress(input, desc="Iterating", unit="it", total=iplen):
97
- self.outputs["do"].set_value(i, does_trigger=False)
98
- triggerstack = TriggerStack()
99
- await self.outputs["do"].trigger(triggerstack)
108
+ self.outputs["do"].set_value(i, does_trigger=True)
109
+ datapaths = [
110
+ ip.datapath
111
+ for ip in self.outputs["do"].connections
112
+ if ip.datapath is not None
113
+ ]
114
+
115
+ while datapaths:
116
+ for dp in datapaths:
117
+ if dp.done(breaking_nodes=[self]):
118
+ datapaths.remove(dp)
119
+ break
120
+ else:
121
+ await asyncio.sleep(0.1)
122
+
100
123
  v = self.inputs["collector"].value
101
124
  if v is not NoValue:
102
125
  results.append(v)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: funcnodes-basic
3
- Version: 0.2.2
3
+ Version: 0.2.4
4
4
  Summary: Basic functionalities for funcnodes
5
5
  Author-email: Julian Kimmig <julian.kimmig@linkdlab.de>
6
6
  License: AGPL-3.0
@@ -12,7 +12,7 @@ Classifier: License :: OSI Approved :: GNU Affero General Public License v3 or l
12
12
  Requires-Python: >=3.11
13
13
  Description-Content-Type: text/markdown
14
14
  License-File: LICENSE
15
- Requires-Dist: funcnodes-core>=0.3.9
15
+ Requires-Dist: funcnodes-core>=0.4.1
16
16
  Requires-Dist: funcnodes
17
17
  Dynamic: license-file
18
18
 
@@ -0,0 +1,14 @@
1
+ funcnodes_basic/__init__.py,sha256=J9x7KEw491QUEh5Uwac9DrwOI0xJydob365Xo3vB3Lo,660
2
+ funcnodes_basic/dataclass.py,sha256=p7IjTek7XnHOxZCJnFHhmNtmYM1DpacmfuaUePvDQ7Y,1732
3
+ funcnodes_basic/dicts.py,sha256=koNJEwIq9ryC7evBpnI-QmR7MBIbgUWqpPpwhB3M69Y,2507
4
+ funcnodes_basic/input.py,sha256=FSHS1bIJ2dJc9NqWaJO0MxegRBERhfxFdkmDiwAuE6o,1654
5
+ funcnodes_basic/lists.py,sha256=9kGnovK-oClFatslbIeYne27l2-EPEXZbr_6yQ1B1cY,5835
6
+ funcnodes_basic/logic.py,sha256=HrJzM9h34PJUWiULU9Ol5iQ2tI6rl7c39iTt6RO6mRg,4952
7
+ funcnodes_basic/math_nodes.py,sha256=PasNf-1wAvbJ_c-_qeiIDaUVfgPQEREJApeUcTS4FQg,10586
8
+ funcnodes_basic/strings.py,sha256=O6rcxBQJ5eYd765w_tolaD6xMwsNmtBjiPgJ_69tKyA,16429
9
+ funcnodes_basic-0.2.4.dist-info/licenses/LICENSE,sha256=21Lj2q2SYKHMY4768_a3pr3q0jY2VYamAHipoodhMDc,34273
10
+ funcnodes_basic-0.2.4.dist-info/METADATA,sha256=Y6AOiZG7PW9kf_TEg2NJ0lTN50eAAaU67lmKc08JSNk,2001
11
+ funcnodes_basic-0.2.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ funcnodes_basic-0.2.4.dist-info/entry_points.txt,sha256=HZ0g1oDO8PrL_f6b09lfTrS-jXqbZrP0qYf1Km_pVxw,79
13
+ funcnodes_basic-0.2.4.dist-info/top_level.txt,sha256=xYbcX5Jx-Ow3N3kgXtyvh8kuhCahb3eHBIZfMvkpVKI,16
14
+ funcnodes_basic-0.2.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,13 +0,0 @@
1
- funcnodes_basic/__init__.py,sha256=-Y8ZnYjuERjcJ1JET2VMwT3l8OVXgO_q16Af-ViZ3YA,583
2
- funcnodes_basic/dicts.py,sha256=koNJEwIq9ryC7evBpnI-QmR7MBIbgUWqpPpwhB3M69Y,2507
3
- funcnodes_basic/input.py,sha256=FSHS1bIJ2dJc9NqWaJO0MxegRBERhfxFdkmDiwAuE6o,1654
4
- funcnodes_basic/lists.py,sha256=9kGnovK-oClFatslbIeYne27l2-EPEXZbr_6yQ1B1cY,5835
5
- funcnodes_basic/logic.py,sha256=YwIcAgDqxnmJoLVN_hk9XgqrOJvkx3zczx2DxgBliHU,4304
6
- funcnodes_basic/math_nodes.py,sha256=PasNf-1wAvbJ_c-_qeiIDaUVfgPQEREJApeUcTS4FQg,10586
7
- funcnodes_basic/strings.py,sha256=O6rcxBQJ5eYd765w_tolaD6xMwsNmtBjiPgJ_69tKyA,16429
8
- funcnodes_basic-0.2.2.dist-info/licenses/LICENSE,sha256=21Lj2q2SYKHMY4768_a3pr3q0jY2VYamAHipoodhMDc,34273
9
- funcnodes_basic-0.2.2.dist-info/METADATA,sha256=bsn7Tm2o61wEtJ8v4qTFdiEklTu7o0-KjHQJuqaVsiM,2001
10
- funcnodes_basic-0.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
11
- funcnodes_basic-0.2.2.dist-info/entry_points.txt,sha256=HZ0g1oDO8PrL_f6b09lfTrS-jXqbZrP0qYf1Km_pVxw,79
12
- funcnodes_basic-0.2.2.dist-info/top_level.txt,sha256=xYbcX5Jx-Ow3N3kgXtyvh8kuhCahb3eHBIZfMvkpVKI,16
13
- funcnodes_basic-0.2.2.dist-info/RECORD,,