[Pather] fix using trees when append=True
This commit is contained in:
parent
6cf9600193
commit
bdc4dfdd06
3 changed files with 136 additions and 2 deletions
|
|
@ -16,7 +16,7 @@ from numpy import pi
|
|||
from numpy.typing import ArrayLike
|
||||
|
||||
from ..pattern import Pattern
|
||||
from ..library import ILibrary, TreeView
|
||||
from ..library import ILibrary, TreeView, SINGLE_USE_PREFIX
|
||||
from ..error import BuildError, PortError
|
||||
from ..ports import PortList, Port
|
||||
from ..abstract import Abstract
|
||||
|
|
@ -1067,9 +1067,24 @@ class Pather(PortList):
|
|||
tool_port_names = ('A', 'B')
|
||||
pat = Pattern()
|
||||
|
||||
def validate_tree(portspec: str, batch: list[RenderStep], tree: ILibrary) -> None:
|
||||
missing = sorted(
|
||||
name
|
||||
for name in tree.dangling_refs(tree.top())
|
||||
if isinstance(name, str) and name.startswith(SINGLE_USE_PREFIX)
|
||||
)
|
||||
if not missing:
|
||||
return
|
||||
|
||||
tool_name = type(batch[0].tool).__name__
|
||||
raise BuildError(
|
||||
f'Tool {tool_name}.render() returned missing single-use refs for {portspec}: {missing}'
|
||||
)
|
||||
|
||||
def render_batch(portspec: str, batch: list[RenderStep], append: bool) -> None:
|
||||
assert batch[0].tool is not None
|
||||
tree = batch[0].tool.render(batch, port_names=tool_port_names)
|
||||
validate_tree(portspec, batch, tree)
|
||||
name = self.library << tree
|
||||
if portspec in pat.ports:
|
||||
del pat.ports[portspec]
|
||||
|
|
|
|||
|
|
@ -451,7 +451,9 @@ class Tool:
|
|||
else:
|
||||
continue
|
||||
|
||||
pat.plug(seg_tree.top_pattern(), {port_names[1]: port_names[0]}, append=True)
|
||||
seg_name = lib << seg_tree
|
||||
pat.plug(lib[seg_name], {port_names[1]: port_names[0]}, append=True)
|
||||
del lib[seg_name]
|
||||
|
||||
return lib
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue