"""Central resource registry and process-wide factory.The :class:`ResourceRegistry` aggregates every:class:`ResourceRepository` the project exposes. The:func:`resources` factory builds the registry once per process;subsequent calls return the cached instance. Tests that override:class:`aeat.core.config.Settings` to change the bundled-datalocation must call ``resources.cache_clear()`` to force a rebuildon the next access."""from__future__importannotationsfromdataclassesimportdataclass,fieldfromfunctoolsimportcachefrom._reposimport(ApoderamientosRepository,CategoryProfileRepository,HolidayCalendarRepository,IvaCatalogueRepository,IvaRateTableRepository,LegalParameterRepository,ManualRepository,RecargoBandsRepository,TopicCatalogueRepository,UserProfileSchemaRepository,)from._repos.modelosimportStaticModeloRepository
[docs]@dataclass(slots=True,frozen=True)classResourceRegistry:"""Aggregate of every Repository the project exposes. Each field holds one :class:`ResourceRepository` instance owning its own Identity Map. The :meth:`clear` method empties every Repository's cache uniformly; tests that override Settings between cases call it via the module-level :func:`resources` factory's ``cache_clear``. """apoderamientos:ApoderamientosRepository=field(default_factory=ApoderamientosRepository)category_profiles:CategoryProfileRepository=field(default_factory=CategoryProfileRepository)holiday_calendars:HolidayCalendarRepository=field(default_factory=HolidayCalendarRepository)legal_parameters:LegalParameterRepository=field(default_factory=LegalParameterRepository)manuals:ManualRepository=field(default_factory=ManualRepository)modelos:StaticModeloRepository=field(default_factory=StaticModeloRepository)recargo_bands:RecargoBandsRepository=field(default_factory=RecargoBandsRepository)topics:TopicCatalogueRepository=field(default_factory=TopicCatalogueRepository)user_profile_schema:UserProfileSchemaRepository=field(default_factory=UserProfileSchemaRepository)iva_catalogues:IvaCatalogueRepository=field(default_factory=IvaCatalogueRepository)iva_rate_tables:IvaRateTableRepository=field(default_factory=IvaRateTableRepository)
[docs]defclear(self)->None:"""Clear every Repository's Identity Map."""from._repositoryimportResourceRepositoryforattrinself.__dataclass_fields__:value=getattr(self,attr)ifisinstance(value,ResourceRepository):value.clear_cache()
[docs]@cachedefresources()->ResourceRegistry:"""Return the process-wide resource registry. Cached at first call. The factory reads Settings once at construction and threads operator-supplied roots through to the Repositories that honour an env-override seam (manuals and iva catalogues). Tests that mutate Settings between cases call ``resources.cache_clear()`` to rebuild with the new values. Returns: The process-wide cached :class:`ResourceRegistry` instance. """from..configimportload_settingssettings=load_settings()returnResourceRegistry(manuals=ManualRepository(root=settings.aeat_manuals_root),iva_catalogues=IvaCatalogueRepository(root=settings.aeat_iva_catalogue_root),)