Skip to content
Merged

Dev #30

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "test*.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false
}
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## v0.2.4 (2025-06-05)

### Fix

- **dependencies**: 🐛 update `funcnodes-core` version to `0.4.1`
- **logic**: 🐛 improve async handling in WhileNode and ForNode
- **dependencies**: update funcnodes-core version to 0.4.0

## v0.1.6 (2024-08-28)
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[project]
name = "funcnodes-basic"
version = "0.2.3"
version = "0.2.4"
description = "Basic functionalities for funcnodes"
readme = "README.md"
classifiers = [ "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",]
requires-python = ">=3.11"
dependencies = [
"funcnodes-core>=0.3.9",
"funcnodes-core>=0.4.1",
"funcnodes",
]
authors = [{name = "Julian Kimmig", email = "julian.kimmig@linkdlab.de"}]
Expand Down Expand Up @@ -43,3 +43,10 @@ shelf = "funcnodes_basic:NODE_SHELF"

[tool.setuptools.packages.find]
where = [ "src",]

[tool.commitizen]
name = "cz_conventional_commits"
tag_format = "v$version"
version_scheme = "pep440"
version_provider = "uv"
update_changelog_on_bump = true
35 changes: 29 additions & 6 deletions src/funcnodes_basic/logic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Logic Nodes for control flow and decision making."""

from funcnodes_core.node import Node, TriggerStack
from funcnodes_core.node import Node
from typing import Any, List, Optional
from funcnodes_core.io import NodeInput, NodeOutput, NoValue
import asyncio
Expand Down Expand Up @@ -35,8 +35,19 @@ class WhileNode(Node):
async def func(self, condition: bool, input: Any) -> None:
if self.inputs["condition"].value:
self.outputs["do"].value = input
triggerstack = TriggerStack()
await self.outputs["do"].trigger(triggerstack)
datapaths = [
ip.datapath
for ip in self.outputs["do"].connections
if ip.datapath is not None
]

while datapaths:
for dp in datapaths:
if dp.done(breaking_nodes=[self]):
datapaths.remove(dp)
break
else:
await asyncio.sleep(0.1)
self.request_trigger()
else:
self.outputs["done"].value = input
Expand Down Expand Up @@ -94,9 +105,21 @@ async def func(self, input: list, collector: Optional[Any] = None) -> None:
pass

for i in self.progress(input, desc="Iterating", unit="it", total=iplen):
self.outputs["do"].set_value(i, does_trigger=False)
triggerstack = TriggerStack()
await self.outputs["do"].trigger(triggerstack)
self.outputs["do"].set_value(i, does_trigger=True)
datapaths = [
ip.datapath
for ip in self.outputs["do"].connections
if ip.datapath is not None
]

while datapaths:
for dp in datapaths:
if dp.done(breaking_nodes=[self]):
datapaths.remove(dp)
break
else:
await asyncio.sleep(0.1)

v = self.inputs["collector"].value
if v is not NoValue:
results.append(v)
Expand Down
26 changes: 26 additions & 0 deletions tests/test_flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from funcnodes_basic import logic, strings
import pytest_funcnodes
import asyncio


@pytest_funcnodes.nodetest(logic.ForNode)
async def test_if_node_flow1():
fornode = logic.ForNode()
endswith = strings.string_endswith()
ifnode = logic.IfNode()

fornode.outputs["do"].connect(endswith.inputs["s"])
endswith.outputs["ends_with"].connect(ifnode.inputs["condition"])
fornode.outputs["do"].connect(ifnode.inputs["input"])
ifnode.outputs["on_true"].connect(fornode.inputs["collector"])

endswith.inputs["suffix"].value = ".txt"
fornode.inputs["input"].value = ["a.txt", "b.xls", "c.xls", "d.txt", "e.xls"]

# await fn.run_until_complete(fornode, ifnode, endswith)
await asyncio.sleep(1.5)
print("fornode:", fornode.in_trigger)
print("ifnode:", ifnode.in_trigger)
print("endswith:", endswith.in_trigger)

assert fornode.outputs["done"].value == ["a.txt", "d.txt"]
6 changes: 5 additions & 1 deletion tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ async def test_wait_node():
@pytest_funcnodes.nodetest(logic.ForNode)
async def test_for_node():
node = logic.ForNode()
waitnode = logic.WaitNode()
waitnode.inputs["delay"].value = 0.5
waitnode.inputs["input"].connect(node.outputs["do"])
waitnode.outputs["output"].connect(node.inputs["collector"])
node.inputs["input"].value = "hello"
node.outputs["do"].connect(node.inputs["collector"])

await node

assert node.outputs["done"].value == ["h", "e", "l", "l", "o"]
Expand Down
10 changes: 5 additions & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.