[pather] handle paths without existing ports

This commit is contained in:
Jan Petykiewicz 2026-04-08 22:33:07 -07:00
commit 02f0833fb3
2 changed files with 81 additions and 14 deletions

View file

@ -170,24 +170,25 @@ class Pather(PortList):
#
# Core Pattern Operations (Immediate)
#
def _record_break(self, names: Iterable[str | None]) -> None:
""" Record a batch-breaking step for the specified ports. """
if not self._dead:
for n in names:
if n is not None and n in self.paths:
port = self.ports[n]
self.paths[n].append(RenderStep('P', None, port.copy(), port.copy(), None))
def _prepare_break(self, name: str | None) -> tuple[str, RenderStep] | None:
""" Snapshot one batch-breaking step for a name with deferred geometry. """
if self._dead or name is None:
return None
steps = self.paths.get(name)
if not steps:
return None
port = self.ports.get(name, steps[-1].end_port)
return name, RenderStep('P', None, port.copy(), port.copy(), None)
def _prepare_breaks(self, names: Iterable[str | None]) -> list[tuple[str, RenderStep]]:
""" Snapshot break markers to be committed after a successful mutation. """
if self._dead:
return []
prepared: list[tuple[str, RenderStep]] = []
for n in names:
if n is not None and n in self.paths:
port = self.ports[n]
prepared.append((n, RenderStep('P', None, port.copy(), port.copy(), None)))
step = self._prepare_break(n)
if step is not None:
prepared.append(step)
return prepared
def _commit_breaks(self, prepared: Iterable[tuple[str, RenderStep]]) -> None:
@ -246,8 +247,9 @@ class Pather(PortList):
@logged_op(lambda args: list(args['connections'].keys()))
def plugged(self, connections: dict[str, str]) -> Self:
self._record_break(chain(connections.keys(), connections.values()))
prepared_breaks = self._prepare_breaks(chain(connections.keys(), connections.values()))
self.pattern.plugged(connections)
self._commit_breaks(prepared_breaks)
return self
@logged_op(lambda args: list(args['mapping'].keys()))