Source code for aeat.application.modelo._registry_resources
"""Registry resource helpers shared by modelo application actions.Modelo application services access the packaged registry through the central:class:`ValidatedRegistryAuthority` exposed by ``resources().modelos.authority``.This module keeps that access path in one place for work-unit creation,calculation, verification, import, and comparison code that needs the bundled``registry/aeat`` tree or its cached authority.The revision and period guards are create-work-unit checks: they reject userinput that names a modelo revision or filing period the committed registry doesnot declare, before a work unit records a law-determined registry identity.See Also: :mod:`aeat.core.resources`: Owns the packaged resource registry and bundled-path resolution. :class:`aeat.domain.calculations.registry.ValidatedRegistryAuthority`: Loads and validates modelo definitions, then serves registry snapshots. :mod:`aeat.application.modelo._registry_helpers`: Uses this authority helper for import/amendment registry checks."""from__future__importannotationsfrompathlibimportPathfromtypingimportTYPE_CHECKINGfrom...coreimportPeriodfrom...domain.modelosimportModeloErrorifTYPE_CHECKING:from...domain.calculations.registryimportValidatedRegistryAuthority
[docs]defregistry_root()->Path:"""Return the bundled ``registry/aeat`` root used by modelo services. The returned :class:`~pathlib.Path` is the path passed to registry-facing errors when the packaged registry cannot be loaded. It intentionally mirrors the root used by :func:`authority_via_resources`. """from...core.resourcesimportbundled_pathreturnbundled_path("registry","aeat")
[docs]defauthority_via_resources()->ValidatedRegistryAuthority:"""Return the central :class:`ValidatedRegistryAuthority` for modelo registry access. Callers use this instead of constructing a local authority so calculation, verification, import, and create-work-unit paths share the same packaged registry cache and source-root configuration. """from...core.resourcesimportresourcesreturnresources().modelos.authority
[docs]defreject_unknown_revision(*,modelo:str,revision_id:str)->None:"""Refuse a work-unit create that names an undeclared revision id. The central :class:`ValidatedRegistryAuthority` first resolves the modelo definition. If the modelo exists but ``revision_id`` is absent from its revision map, this raises :class:`ModeloError` with the available revision ids. """from...domain.calculations.registryimportRegistrySnapshotErrortry:modelo_def=authority_via_resources().modelo(modelo)exceptRegistrySnapshotErrorasexc:raiseModeloError(str(exc))fromexcifrevision_idinmodelo_def.revisions:returnavailable=", ".join(sorted(modelo_def.revisions))raiseModeloError(f"revision_id {revision_id!r} is not declared on modelo {modelo!r}. Available revisions: {available}",)
[docs]defreject_unknown_period_for_revision(*,modelo:str,revision_id:str,period:Period)->None:"""Refuse a work-unit create whose :class:`Period` is absent from the revision schedules. The guard inspects the named revision's filing schedules and compares the caller's ``period.registry_token`` to the declared period tokens. A revision with no declared schedule is accepted here; a missing revision is also left alone because :func:`reject_unknown_revision` owns that refusal. """from...domain.calculations.registryimportRegistrySnapshotErrortry:modelo_def=authority_via_resources().modelo(modelo)exceptRegistrySnapshotErrorasexc:raiseModeloError(str(exc))fromexcrevision=modelo_def.revisions.get(revision_id)ifrevisionisNone:returndeclared:set[str]=set()forscheduleinrevision.filing_schedules:declared.update(schedule.periods)ifnotdeclaredorperiod.registry_tokenindeclared:returnavailable=", ".join(sorted(declared))raiseModeloError(f"period {period.registry_token!r} is not declared on modelo {modelo!r} "f"revision {revision_id!r}. Available periods: {available}",)