Source code for jitx.run.configuration
"""The configuration of a design held by the runtime.
Reached through ``RuntimeDesign.configuration``. Requests change settings of
the design that apply on its next load, such as its reference designators.
"""
from __future__ import annotations
from collections.abc import Awaitable, Callable, Mapping
import jitxcore._proto.configuration_pb2 as cpb2
from jitx.component import Component
from .._translate.idmap import ReverseMapper, stable_id_proto
def _reassign_reference_designators(
rmap: ReverseMapper, designators: Mapping[Component, str]
) -> cpb2.ConfigurationOperations:
assignments = []
for component, designator in designators.items():
key = rmap.stable_id_of(component)
if key is None or len(key) != 1:
raise ValueError(f"the runtime has no ID for component {component}")
assignments.append(
cpb2.ReferenceDesignatorAssignment(
instance=stable_id_proto(key[0]), designator=designator
)
)
reassign = cpb2.ReassignReferenceDesignators(assignments=assignments)
return cpb2.ConfigurationOperations(
operations=[
cpb2.ConfigurationOperation(reassign_reference_designators=reassign)
]
)
[docs]
class AsyncConfiguration:
"""The configuration of an async runtime design."""
def __init__(
self,
rmap: Callable[[], ReverseMapper],
send: Callable[
[cpb2.ConfigurationOperations],
Awaitable[cpb2.ConfigurationOperationsResponse],
],
):
self.__rmap = rmap
self.__send = send
[docs]
async def reassign_reference_designators(
self, designators: Mapping[Component, str], /
) -> None:
"""Replace the reference designators of the design. This does not update
the live model. The new designators show on the design after another
:py:meth:`~jitx.run.runtime.Runtime.submit`.
Args:
designators: The new designator of every component whose
designator is not set in code.
Raises:
ValueError: if the runtime has no ID for a component.
RequestRejected: if the runtime refused the designators.
"""
await self.__send(_reassign_reference_designators(self.__rmap(), designators))
[docs]
class SyncConfiguration:
"""The configuration of a sync runtime design."""
def __init__(
self,
rmap: Callable[[], ReverseMapper],
send: Callable[
[cpb2.ConfigurationOperations], cpb2.ConfigurationOperationsResponse
],
):
self.__rmap = rmap
self.__send = send
[docs]
def reassign_reference_designators(
self, designators: Mapping[Component, str], /
) -> None:
"""Replace the reference designators of the design. See
:py:meth:`AsyncConfiguration.reassign_reference_designators`."""
self.__send(_reassign_reference_designators(self.__rmap(), designators))