Skip to content

Commit

Permalink
Render stuff in alphabetical order by default
Browse files Browse the repository at this point in the history
Consistent ordering is important for testing examples, which need reliable output. Otherwise has no real input as it only impacts the render.
  • Loading branch information
liamhuber committed Jan 11, 2024
1 parent f27223a commit 43e5716
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pyiron_ontology/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
A tree structure for ontologically-informed workflows
"""

from numpy import argsort


class NodeTree:
def __init__(self, value, parent=None):
Expand All @@ -14,8 +16,13 @@ def __init__(self, value, parent=None):
if parent is not None:
parent.children.append(self)

def render(self, depth=0):
def render(self, depth=0, order_alphabetically=True):
tabs = "".join(["\t"] * depth)
print(f"{tabs}{self.value.name}")
for child in self.children:
children = (
[self.children[n] for n in argsort([str(c.value) for c in self.children])]
if order_alphabetically
else self.children
)
for child in children:
child.render(depth=depth + 1)

0 comments on commit 43e5716

Please sign in to comment.