[Pather] fix port rename/deletion tracking

This commit is contained in:
Jan Petykiewicz 2026-03-31 18:49:41 -07:00
commit 2b29e46b93
3 changed files with 63 additions and 4 deletions

View file

@ -228,7 +228,17 @@ class Pather(PortList):
@logged_op(lambda args: list(args['mapping'].keys()))
def rename_ports(self, mapping: dict[str, str | None], overwrite: bool = False) -> Self:
self.pattern.rename_ports(mapping, overwrite)
renamed: dict[str, list[RenderStep]] = {vv: self.paths.pop(kk) for kk, vv in mapping.items() if kk in self.paths and vv is not None}
renamed: dict[str, list[RenderStep]] = {}
for kk, vv in mapping.items():
if kk not in self.paths:
continue
steps = self.paths.pop(kk)
# Preserve deferred geometry even if the live port is deleted.
# `render()` can still materialize the saved steps using their stored start/end ports.
# Current semantics intentionally keep deleted ports' queued steps under the old key,
# so if a new live port later reuses that name it does not retarget the old geometry;
# the old and new routes merely share a render bucket until `render()` consumes them.
renamed[kk if vv is None else vv] = steps
self.paths.update(renamed)
return self
@ -789,6 +799,9 @@ class PortPather:
#
# Delegate to port
#
# These mutate only the selected live port state. They do not rewrite already planned
# RenderSteps, so deferred geometry remains as previously planned and only future routing
# starts from the updated port.
def set_ptype(self, ptype: str) -> Self:
for port in self.ports:
self.pather.pattern[port].set_ptype(ptype)
@ -865,8 +878,7 @@ class PortPather:
def drop(self) -> Self:
""" Remove selected ports from the pattern and the PortPather. """
for pp in self.ports:
del self.pather.pattern.ports[pp]
self.pather.rename_ports({pp: None for pp in self.ports})
self.ports = []
return self
@ -880,7 +892,7 @@ class PortPather:
if name is None:
self.drop()
return None
del self.pather.pattern.ports[name]
self.pather.rename_ports({name: None})
self.ports = [pp for pp in self.ports if pp != name]
return self