Avoid generating a container if only a single port is passed

This commit is contained in:
Jan Petykiewicz 2022-03-01 18:53:37 -08:00 committed by jan
parent 885b259fb7
commit f834ec6be5

View File

@ -839,7 +839,8 @@ class Device(Copyable, Mirrorable):
spacing: Optional[Union[float, ArrayLike]] = None,
set_rotation: Optional[float] = None,
tool_port_names: Sequence[str] = ('A', 'B'),
name: str = '_busL',
container_name: str = '_busL',
force_container: bool = False,
**kwargs,
) -> D:
if self._dead:
@ -867,10 +868,14 @@ class Device(Copyable, Mirrorable):
extensions = ell(ports, ccw, spacing=spacing, bound=bound, bound_type=bound_type, set_rotation=set_rotation)
dev = Device(name='', ports=ports, tools=self.tools).as_interface(name)
if len(ports) == 1 and not force_container:
# Not a bus, so having a container just adds noise to the layout
port_name = tuple(portspec)[0]
return self.path(port_name, ccw, extensions[port_name], tool_port_names=tool_port_names)
else:
dev = Device(name='', ports=ports, tools=self.tools).as_interface(container_name)
for name, length in extensions.items():
dev.path(name, ccw, length, tool_port_names=tool_port_names)
return self.plug(dev, {sp: 'in_' + sp for sp in ports.keys()}) # TODO safe to use 'in_'?
# TODO def path_join() and def bus_join()?