Skip to content

Commit

Permalink
Merge pull request #206 from pyiron/fix_registration
Browse files Browse the repository at this point in the history
  • Loading branch information
liamhuber authored Feb 15, 2024
2 parents 344d1c4 + 37f8858 commit 63d9288
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
17 changes: 12 additions & 5 deletions pyiron_workflow/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ + "."
):
Expand All @@ -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)

Expand Down
Empty file.
16 changes: 16 additions & 0 deletions tests/static/nodes_subpackage/subsub_sibling/demo_nodes.py
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions tests/unit/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 63d9288

Please sign in to comment.