aeat.domain.calculations.registry._loader module

Read-only TOML loader for AEAT registry definitions.

Compiles TOML authoring fragments into strict runtime objects. Each ModeloDefinition is assembled from one TOML file or a directory manifest; each ModeloRevision is compiled from a single revision file or a set of append fragments merged in deterministic order.

class ModeloRevisionSource(revision_id, layout, path, fragment_paths)[source]

Bases: object

On-disk source for one modelo revision before schema validation.

Parameters:
  • revision_id (str)

  • layout (Literal['revision_file', 'fragment_directory'])

  • path (Path)

  • fragment_paths (tuple[Path, ...])

revision_id: str
layout: Literal['revision_file', 'fragment_directory']
path: Path
fragment_paths: tuple[Path, ...]
class ModeloSource(modelo_id, layout, path, manifest_path, revision_sources=())[source]

Bases: object

On-disk source for one modelo before schema validation.

Parameters:
modelo_id: str
layout: Literal['single_file', 'directory']
path: Path
manifest_path: Path
revision_sources: tuple[ModeloRevisionSource, ...]
load_modelo_file(path)[source]

Load one modelo TOML file into strict schema objects.

Return type:

ModeloDefinition

Returns:

The compiled ModeloDefinition from the TOML file.

Parameters:

path (Path)

load_modelo_directory(directory)[source]

Load a ModeloDefinition from a directory layout.

The directory must contain manifest.toml carrying the [modelo] metadata table. Per-revision data lives in revisions/{id}.toml files, or in revisions/{id}/ fragment directories. Revision files declare one or more revisions via top-level [revisions."<id>"] (and [[revisions."<id>".X]] array tables). Fragment directories declare exactly the directory revision id across one or more TOML files using the same table shape. All revision sources are merged into the single in-memory ModeloDefinition that single-file mode produces.

Public API stays identical to load_modelo_file: callers receive the same ModeloDefinition regardless of on-disk layout.

Return type:

ModeloDefinition

Parameters:

directory (Path)

load_modelo_path(path)[source]

Load a ModeloDefinition from either supported on-disk layout.

Return type:

ModeloDefinition

Parameters:

path (Path)

load_modelo_source(source)[source]

Load a modelo from a discovered source descriptor.

Return type:

ModeloDefinition

Returns:

The compiled ModeloDefinition from the source.

Parameters:

source (ModeloSource)

load_modelo_directory_without_locales(resolved)[source]

Load a directory-mode ModeloDefinition without applying locale TOML.

Composes the same manifest/revisions/build steps as load_modelo_directory() but skips apply_locales(), for callers (the schema-local locale-authoring CLI) that must read the raw Spanish schema before any translation overlay is injected.

Raises:

RegistryLoadError – If the manifest is missing, malformed, or no revisions are found under resolved/revisions.

Return type:

ModeloDefinition

Parameters:

resolved (Path)

load_catalogue_file(path)[source]

Load one shared legal/source catalogue TOML file.

Return type:

RegistryCatalogues

Returns:

The compiled RegistryCatalogues from the TOML file.

Parameters:

path (Path)

Load only the legal-parameter catalogue from root/legal/*.toml.

Lightweight cycle-safe entry point. Consumers in aeat.domain.iva and aeat.domain.rental need parameter values at module-import time, but the full load_registry_tree() path pulls in _bindings which itself imports from aeat.domain.iva — a circular import.

This function reuses load_catalogue_file() (already Pydantic-validated and lru_cache-deduplicated) and walks only root/legal/*.toml. Modelo parsing and binding validation do not run; the legal refs carried by returned parameters are still resolved against the legal catalogue.

Parameters:

root (Path) – Repository registry/aeat directory.

Return type:

Mapping[str, LegalParameter]

Returns:

Frozen mapping of parameter-id → LegalParameter.

Raises:

RegistryLoadError – When duplicate parameter ids are found across multiple TOML files in root/legal/.

load_registry_tree(root)[source]

Load all registry files from root.

Discovers modelos in two layouts:
  • single-file: modelos/<id>.toml

  • directory: modelos/<id>/manifest.toml + modelos/<id>/revisions/*.toml

A single modelo cannot exist in both layouts simultaneously; the loader raises RegistryLoadError if both forms are present.

Return type:

tuple[tuple[ModeloDefinition, ...], RegistryCatalogues]

Returns:

A tuple of all ModeloDefinition objects and the merged RegistryCatalogues.

Parameters:

root (Path)

discover_modelo_sources(modelos_dir)[source]

Discover ModeloSource layouts under a modelos/ directory.

This is the generic source-layout contract for the registry: callers can reason about single-file modelos, directory-mode modelos, per-revision files, and fragmented revision directories without special-casing a modelo id.

Return type:

tuple[ModeloSource, ...]

Parameters:

modelos_dir (Path)

clear_fingerprint_cache()[source]

Clear the TTL-backed registry-tree fingerprint cache.

Return type:

None