[PortsLibraryView] now accepts overrides
This commit is contained in:
parent
520f37aa29
commit
7083edc7ca
4 changed files with 160 additions and 12 deletions
|
|
@ -20,6 +20,8 @@ if TYPE_CHECKING:
|
|||
|
||||
from numpy.typing import NDArray
|
||||
|
||||
from ..ports import Port
|
||||
|
||||
|
||||
@dataclass
|
||||
class _SourceLayer:
|
||||
|
|
@ -47,7 +49,7 @@ def _materialize_detached_pattern(view: ILibraryView, name: str) -> Pattern:
|
|||
|
||||
class PortsLibraryView(ILibraryView):
|
||||
"""
|
||||
Read-only view which imports ports into cells on first materialization.
|
||||
Read-only view which imports or applies ports on first materialization.
|
||||
|
||||
The wrapped source remains untouched; this view owns a separate processed
|
||||
cache so direct-copy workflows can continue to use the raw source view.
|
||||
|
|
@ -61,14 +63,21 @@ class PortsLibraryView(ILibraryView):
|
|||
self,
|
||||
source: ILibraryView,
|
||||
*,
|
||||
layers: Sequence[layer_t],
|
||||
layers: Sequence[layer_t] = (),
|
||||
max_depth: int = 0,
|
||||
skip_subcells: bool = True,
|
||||
ports: Mapping[str, Mapping[str, Port]] | None = None,
|
||||
replace: bool = False,
|
||||
) -> None:
|
||||
self._source = source
|
||||
self._layers = tuple(layers)
|
||||
self._max_depth = max_depth
|
||||
self._skip_subcells = skip_subcells
|
||||
self._ports = {
|
||||
name: copy.deepcopy(dict(cell_ports))
|
||||
for name, cell_ports in (ports or {}).items()
|
||||
}
|
||||
self._replace = replace
|
||||
self._cache: dict[str, Pattern] = {}
|
||||
self._lookups_in_progress: list[str] = []
|
||||
if hasattr(source, 'library_info'):
|
||||
|
|
@ -103,14 +112,21 @@ class PortsLibraryView(ILibraryView):
|
|||
self._lookups_in_progress.append(name)
|
||||
try:
|
||||
pat = _materialize_detached_pattern(self._source, name)
|
||||
pat = data_to_ports(
|
||||
layers=self._layers,
|
||||
library=self,
|
||||
pattern=pat,
|
||||
name=name,
|
||||
max_depth=self._max_depth,
|
||||
skip_subcells=self._skip_subcells,
|
||||
)
|
||||
if self._layers:
|
||||
pat = data_to_ports(
|
||||
layers=self._layers,
|
||||
library=self,
|
||||
pattern=pat,
|
||||
name=name,
|
||||
max_depth=self._max_depth,
|
||||
skip_subcells=self._skip_subcells,
|
||||
)
|
||||
if name in self._ports:
|
||||
ports = copy.deepcopy(self._ports[name])
|
||||
if self._replace:
|
||||
pat.ports = ports
|
||||
else:
|
||||
pat.ports.update(ports)
|
||||
finally:
|
||||
self._lookups_in_progress.pop()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue