aeat.domain.manuals._loader module¶
File-backed loader and query API for aeat.domain.manuals.
The loader walks the corpus/manuals/ directory hierarchy and
produces strictly-validated Manual,
Chapter, and
Section records. Tests exercise it
against hand-crafted temporary-directory fixtures so the contract is
locked for downstream extraction work that lands real chapter trees.
Directory shape per part root:
<part_root>/
source.pdf # git-ignored, raw binary
manifest.json # FetchedManualPart record (committed)
structure/
manual.json # Manual metadata (without embedded chapters)
chapters.json # tuple[Chapter, ...] with SectionRef entries
sections/<chapter-id>/<section-id>.json # Section records
For IVA (ManualPart.SINGLE) the <part_root> is
corpus/manuals/iva/<year>/; for Renta the part root is nested
inside the canonical ManualPart directory value.
- resolve_part_root(*, manual_id, year, part, settings=None)[source]¶
Return the on-disk root for a specific
(manual_id, year, part).- Parameters:
manual_id (
ManualId) – Handbook identifier.year (
int) – Tax year.part (
ManualPart) – Volume split.SINGLEflattens the directory layout.settings (
Settings|None) – Optional settings instance; loaded on demand otherwise.
- Return type:
Path- Returns:
The canonical directory path (not guaranteed to exist).
- load_manual(manual_id, year, part=ManualPart.SINGLE, *, settings=None)[source]¶
Load a single
Manualfromcorpus/manuals/.- Parameters:
manual_id (
ManualId) – Handbook identifier.year (
int) – Tax year.part (
ManualPart) – Volume split within the year. Defaults toSINGLE.settings (
Settings|None) – Optional settings instance; loaded on demand otherwise.
- Return type:
- Returns:
A fully validated
Manualincluding its chapter tree (but not resolved section bodies — those are loaded lazily byload_section()or iterated byfind_rules()).- Raises:
ManualNotFoundError – If the required metadata files are absent.
- load_section(part_root, section_ref)[source]¶
Load a single
Sectionby resolvingsection_refon disk.- Parameters:
part_root (
Path) – Directory root for the owning manual part.section_ref (
SectionRef) – Pointer returned by the owningChapter.
- Return type:
- Returns:
A fully validated
Sectionrecord.- Raises:
ManualParseError – If the file path escapes the manual root or fails schema validation.
- load_catalogue(specs, *, settings=None)[source]¶
Load every requested
(manual_id, year, part)into a catalogue.- Parameters:
- Return type:
- Returns:
A
ManualCataloguecontaining every successfully loadedManual. Missing specifiers raise immediately; partial loads are not supported so the catalogue always reflects a coherent on-disk state.
- iter_sections(manual, *, settings=None)[source]¶
Yield every
Sectionbelonging tomanual, in tree order.
- find_rules(catalogue, *, casilla_reference=None, kind=None, lang=None, settings=None)[source]¶
Iterate every
Ruleincataloguematching the filters.- Parameters:
catalogue (
ManualCatalogue) – A loadedManualCatalogue.casilla_reference (
ManualCasillaReference|None) – Optional structured modelo/casilla filter. Rules whosereferences_casillasdoes not contain this value are skipped.kind (
Optional[Literal['computation','applicability','valuation','deductibility','formal_obligation','procedural','other']]) – OptionalRuleKindfilter.lang (
str|None) – Optionalstrfilter. When provided, rules whose statement cannot be resolved intolangunder the configured fallback policy are skipped.
- Yields:
Rulerecords matching every supplied filter.- Return type: