Source code for aeat.core.resources._repos.modelos
"""StaticModeloRepository: thin façade over ValidatedRegistryAuthority.The modelos repository is the only one that backs onto anaggregate (:class:`ValidatedRegistryAuthority`) rather than a directloader. The authority owns the validator + snapshot caches thatthe test suite already relies on; the Repository preservesthose caches by holding a reference to the authority instanceand delegating ``get`` / ``all`` through it. Both return:class:`ModeloDefinition` records resolved from the authority."""from__future__importannotationsfrompathlibimportPathfromtypingimportTYPE_CHECKING,overridefrom.._errorsimportResourceNotFoundErrorfrom.._repositoryimportResourceCacheRepositoryifTYPE_CHECKING:from....domain.calculations.registryimportModeloDefinition,ValidatedRegistryAuthority
[docs]classStaticModeloRepository(ResourceCacheRepository["ModeloDefinition",str]):"""Modelo definitions keyed by their typed id (``"100"``, ``"180"``, …). Wraps :class:`aeat.domain.calculations.registry.ValidatedRegistryAuthority`. The authority is constructed lazily on first ``get`` so the bundled registry only loads when actually needed. """def__init__(self,root:Path|None=None,source_root:Path|None=None)->None:super().__init__()self._root=rootself._source_root=source_rootself._authority:ValidatedRegistryAuthority|None=Nonedef_resolve_authority(self)->ValidatedRegistryAuthority:ifself._authorityisnotNone:returnself._authorityfrom....domain.calculations.registryimport(ValidatedRegistryAuthorityas_ValidatedRegistryAuthority,)from.._boundaryimportbundled_pathroot=self._rootorbundled_path("registry","aeat")source_root=self._source_rootorbundled_path()self._authority=_ValidatedRegistryAuthority.load(root,source_root=source_root)returnself._authority@propertydefauthority(self)->ValidatedRegistryAuthority:"""Return the backing :class:`ValidatedRegistryAuthority` instance."""returnself._resolve_authority()@overridedef_load(self,key:str)->ModeloDefinition:from....domain.calculations.registryimportRegistrySnapshotErrorauthority=self._resolve_authority()try:returnauthority.modelo(key)exceptRegistrySnapshotErrorasexc:raiseResourceNotFoundError(f"no modelo definition registered for {key!r}")fromexc
[docs]@overridedefall(self)->tuple[ModeloDefinition,...]:"""Return every modelo definition in the bundled registry. Returns: A tuple of every :class:`ModeloDefinition` known to the backing authority. """authority=self._resolve_authority()returntuple(authority.modelos)
[docs]@overridedefclear_cache(self)->None:"""Clear the Identity Map AND the backing authority reference."""super().clear_cache()self._authority=None