From 7d8c3545f3c507aba6ffdd8ee402a07e0e460266 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Wed, 14 Feb 2024 16:10:35 -0800 Subject: [PATCH 1/2] Force the problem in the tests --- .../nodes_subpackage/subsub_sibling/__init__.py | 0 .../subsub_sibling/demo_nodes.py | 16 ++++++++++++++++ tests/unit/test_interfaces.py | 1 + 3 files changed, 17 insertions(+) create mode 100644 tests/static/nodes_subpackage/subsub_sibling/__init__.py create mode 100644 tests/static/nodes_subpackage/subsub_sibling/demo_nodes.py diff --git a/tests/static/nodes_subpackage/subsub_sibling/__init__.py b/tests/static/nodes_subpackage/subsub_sibling/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/static/nodes_subpackage/subsub_sibling/demo_nodes.py b/tests/static/nodes_subpackage/subsub_sibling/demo_nodes.py new file mode 100644 index 00000000..533e1005 --- /dev/null +++ b/tests/static/nodes_subpackage/subsub_sibling/demo_nodes.py @@ -0,0 +1,16 @@ +""" +A demo node package for the purpose of testing node package registration. +""" + +from typing import Optional + +from pyiron_workflow import Workflow + + +@Workflow.wrap_as.single_value_node("sum") +def OptionallyAdd(x: int, y: Optional[int] = None) -> int: + y = 0 if y is None else y + return x + y + + +nodes = [OptionallyAdd] diff --git a/tests/unit/test_interfaces.py b/tests/unit/test_interfaces.py index 87442fa1..4281ed4d 100644 --- a/tests/unit/test_interfaces.py +++ b/tests/unit/test_interfaces.py @@ -44,6 +44,7 @@ def test_registration(self): self.creator.register("static.nodes_subpackage", "sub") self.assertIsInstance(self.creator.sub.demo_nodes, NodePackage) self.assertIsInstance(self.creator.sub.subsub_package.demo_nodes, NodePackage) + self.assertIsInstance(self.creator.sub.subsub_sibling.demo_nodes, NodePackage) with self.subTest("Test re-registration"): self.creator.register("static.demo_nodes", "demo") From 37f8858dfdc03eaca9d45ecee8b9e9fc908c9596 Mon Sep 17 00:00:00 2001 From: liamhuber Date: Wed, 14 Feb 2024 17:01:03 -0800 Subject: [PATCH 2/2] Patch registration to make new dictionaries based off the module path --- pyiron_workflow/interfaces.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pyiron_workflow/interfaces.py b/pyiron_workflow/interfaces.py index 90e19338..baff17e0 100644 --- a/pyiron_workflow/interfaces.py +++ b/pyiron_workflow/interfaces.py @@ -243,9 +243,11 @@ def _register_recursively_from_module( if domain is not None: if domain not in container.keys(): container[domain] = DotDict() - subcontainer = container[domain] + container = container[domain] else: - subcontainer = None + container = None + subcontainer = container + for _, submodule_name, _ in pkgutil.walk_packages( module.__path__, module.__name__ + "." ): @@ -260,9 +262,14 @@ def _register_recursively_from_module( submodule, subdomain, subcontainer ) else: - if subdomain not in container.keys(): - subcontainer[subdomain] = DotDict() - subcontainer = subcontainer[subdomain] + relative_path = submodule.__name__.replace( + module.__name__ + ".", "" + ) + subcontainer = container + for step in relative_path.split("."): + if step not in subcontainer.keys(): + subcontainer[step] = DotDict() + subcontainer = subcontainer[subdomain] else: self._register_package_from_module(module, domain, container)