Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repos:
args: ["--branch", "main", "--branch", "master", "--branch", "test"]

- repo: https://github.com/python-poetry/poetry
rev: "1.8.0" # add version here
rev: "2.0.1" # add version here
hooks:
- id: poetry-check
verbose: true
Expand All @@ -20,7 +20,7 @@ repos:

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.7.3
rev: v0.9.1
hooks:
# Run the linter.
- id: ruff
Expand Down
2 changes: 1 addition & 1 deletion funcnodes_basic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .dicts import NODE_SHELF as dicts_shelf


__version__ = "0.2.0"
__version__ = "0.2.1"

NODE_SHELF = Shelf(
nodes=[],
Expand Down
34 changes: 18 additions & 16 deletions funcnodes_basic/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import asyncio

import funcnodes_core as fn
import time


class IfNode(Node):
Expand Down Expand Up @@ -57,17 +58,18 @@ class WaitNode(Node):
output = NodeOutput(id="output", type=Any)

async def func(self, delay: float, input: Optional[Any] = NoValue) -> None:
if delay > 1:
total_seconds = int(delay)
remaining_seconds = delay - total_seconds
self.progress.unit = "s"
self.progress.reset(total=total_seconds)
self.progress.set_description("Waiting")
for _ in range(total_seconds):
await asyncio.sleep(1)
self.progress.update()
await asyncio.sleep(remaining_seconds)
start = time.time()
remaining_seconds = delay

if delay > 1:
with self.progress(desc="Waiting", unit="s", total=delay) as pbar:
while remaining_seconds > 0:
interval = min(remaining_seconds, 1)
await asyncio.sleep(interval)
now = time.time()
elapsed = now - start
remaining_seconds = max(0, delay - elapsed)
pbar.update(interval)
else:
await asyncio.sleep(delay)
self.outputs["output"].value = input
Expand All @@ -85,20 +87,20 @@ async def func(self, input: list, collector: Optional[Any] = None) -> None:
results = []
self.outputs["done"].value = NoValue

iplen = len(input)
self.progress.unit = "it"
self.progress.reset(total=iplen)
self.progress.set_description("Iterating")
iplen = None
try:
iplen = len(input)
except Exception:
pass

for i in input:
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)
v = self.inputs["collector"].value
if v is not NoValue:
results.append(v)
self.inputs["collector"].value = NoValue
self.progress.update()
self.outputs["done"].value = results


Expand Down
629 changes: 359 additions & 270 deletions poetry.lock

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
[tool.poetry]
[project]
name = "funcnodes-basic"
version = "0.2.0"
version = "0.2.1"
description = "Basic functionalities for funcnodes"
authors = ["Julian Kimmig <julian.kimmig@gmx.net>"]
authors = [
{name = "Julian Kimmig", email = "julian.kimmig@linkdlab.de>"}
]
readme = "README.md"
license = "AGPL-3.0"
classifiers = [
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
]

[tool.poetry.urls]
requires-python = ">=3.11"
dependencies = [
"funcnodes-core>=0.3.9",
"funcnodes",
]

[project.urls]
homepage = "https://github.com/Linkdlab/funcnodes_basic"
source = "https://github.com/Linkdlab/funcnodes_basic"
tracker = "https://github.com/Linkdlab/funcnodes_basic/issues"
download = "https://pypi.org/project/funcnodes-basic/#files"


[tool.poetry.dependencies]
python = ">=3.11"
funcnodes-core = ">=0.3.4"
funcnodes = "*"

[tool.poetry.group.dev.dependencies]
pytest = "*"
Expand All @@ -30,6 +34,6 @@ funcnodes-module = "^0.1.19"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry.plugins."funcnodes.module"]
[project.entry-points."funcnodes.module"]
module = "funcnodes_basic"
shelf = "funcnodes_basic:NODE_SHELF"
2 changes: 1 addition & 1 deletion tests/all_nodes_test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,5 @@ def tearDownClass(cls):
# Final assertion to ensure all nodes were tested
if cls.nodes_to_test:
raise AssertionError(
f"These nodes were not tested ({ len(cls.nodes_to_test) }): { cls.nodes_to_test}"
f"These nodes were not tested ({len(cls.nodes_to_test)}): {cls.nodes_to_test}"
)
17 changes: 7 additions & 10 deletions tests/test_dict.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import unittest
from funcnodes_basic import dicts

# DictGetNode,
# dict_keys,
# dict_values,
# dict_items,
# dict_from_items,
# dict_from_keys_values,
# dict_to_list,
# DictGetNode,
# dict_keys,
# dict_values,
# dict_items,
# dict_from_items,
# dict_from_keys_values,
# dict_to_list,


class TestDictMethods(unittest.IsolatedAsyncioTestCase):
Expand Down Expand Up @@ -80,7 +80,6 @@ async def test_dict_from_keys_values(self):

self.assertEqual(node.outputs["out"].value, {"a": 1, "b": 2, "c": 3})


async def test_dict_to_list(self):
testdict = {"a": 1, "b": 2, "c": 3}

Expand All @@ -91,5 +90,3 @@ async def test_dict_to_list(self):

self.assertEqual(node.outputs["keys"].value, ["a", "b", "c"])
self.assertEqual(node.outputs["values"].value, [1, 2, 3])


3 changes: 2 additions & 1 deletion tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,5 @@ async def test_while_node(self):

await while_node

self.assertEqual(subtract_node.outputs["out"].value, 4)
self.assertLessEqual(subtract_node.outputs["out"].value, 5)
self.assertGreaterEqual(subtract_node.outputs["out"].value, 4)
6 changes: 3 additions & 3 deletions tests/test_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import math
import sys

class TestMathNodes(unittest.IsolatedAsyncioTestCase):

class TestMathNodes(unittest.IsolatedAsyncioTestCase):
async def test_value_node(self):
node = math_nodes.value_node()
node.inputs["value"].value = 10.0
Expand Down Expand Up @@ -353,7 +353,6 @@ async def test_math_tanh_node(self):
await node
self.assertEqual(node.outputs["out"].value, math.tanh(0.0))


async def test_math_exp2_node(self):
node = math_nodes.math_exp2_node()
node.inputs["a"].value = 3.0
Expand Down Expand Up @@ -513,9 +512,10 @@ async def test_math_dist_node(self):
self.assertEqual(node.outputs["out"].value, 5.0)

if sys.version_info >= (3, 12):

async def test_math_sumprod_node(self):
node = math_nodes.math_sumprod_node()
node.inputs["a"].value = [1.0, 2.0]
node.inputs["b"].value = [3.0, 4.0]
await node
self.assertEqual(node.outputs["out"].value, 11.0)
self.assertEqual(node.outputs["out"].value, 11.0)
Loading