Skip to content

Commit dc399ec

Browse files
committed
refact(op, netop): helper methd to get op.deps & netop.ops
1 parent c7f45ab commit dc399ec

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

graphtik/netop.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import logging
66
import re
77
from collections import abc
8-
from typing import Any, Callable, Mapping
8+
from typing import Any, Callable, Collection, List, Mapping
99

1010
import networkx as nx
1111
from boltons.setutils import IndexedSet as iset
@@ -161,6 +161,11 @@ def __repr__(self):
161161
)
162162
return f"{clsname}({self.name!r}, needs={needs}, provides={provides}, x{len(ops)} ops: {steps})"
163163

164+
@property
165+
def ops(self) -> List[Operation]:
166+
"""All :term:`operation`\\s contained."""
167+
return list(yield_ops(self.net.graph))
168+
164169
def withset(
165170
self,
166171
outputs: Items = UNSET,

graphtik/op.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import textwrap
99
from collections import abc as cabc
1010
from collections import namedtuple
11-
from typing import Any, Callable, List, Mapping, Set, Tuple, Union
11+
from typing import Any, Callable, Collection, List, Mapping, Set, Tuple, Union
1212

1313
from boltons.setutils import IndexedSet as iset
1414

@@ -352,11 +352,15 @@ def __repr__(self):
352352
)
353353

354354
@property
355-
def deps(self) -> str:
356-
"""Human-readable representation of :term:`dependency` names, both `op_` & `fn_`."""
355+
def deps(self) -> Mapping[str, Collection]:
356+
"""
357+
All :term:`dependency` names, including `op_` & internal `_fn_`.
358+
359+
if not DEBUG, all deps are converted into lists, ready to be printed.
360+
"""
357361

358-
return "\n".join(
359-
f"{k}: {list(v)}"
362+
return {
363+
k: v if is_debug() else list(v)
360364
for k, v in zip(
361365
"needs fn_needs provides op_provides fn_provides".split(),
362366
(
@@ -367,7 +371,7 @@ def deps(self) -> str:
367371
self._fn_provides,
368372
),
369373
)
370-
)
374+
}
371375

372376
def withset(self, **kw) -> "FunctionalOperation":
373377
"""

0 commit comments

Comments
 (0)