aeat.core.resources._boundary module¶
Single boundary for reading bundled corpus and registry data.
Bundled trees live at aeat/_data/corpus/... and
aeat/_data/registry/... inside the installed wheel via the
hatchling force-include configuration in pyproject.toml. The
same prefix resolves to the in-tree top-level corpus/ and
registry/ directories under an editable install because hatchling
honours the force-include mapping for both targets.
Callers MUST go through packaged_data() rather than computing the location
from __file__ or a PROJECT_ROOT walk. Use bundled_path() when a
process-lifetime Path is required, and as_path() for a
scoped materialised path. The PROJECT_ROOT walk is reserved for var/
operator outputs in aeat.core.config and is not a valid resolution path
for read-only bundled data.
The corpus source binaries (_data/corpus/**/*.{pdf,xls,xlsx}) are excluded
from the slim aeat runtime wheel and shipped in an optional aeat_data
companion distribution whose layout mirrors aeat/_data. resolve_corpus_binary()
is the single importlib.resources seam that resolves such a binary from the
aeat tree first and then the companion, so a full checkout and a split
install read a corpus binary uniformly; resolve_companion_binary()
resolves the companion side alone. A missing companion is a not-present signal
(None), never an exception leak.
- packaged_data(*parts)[source]¶
Return a Traversable rooted at
aeat/_data/<parts...>.- Parameters:
*parts (
str) – One or more path segments joined under the bundled data root. Empty call returns the bundled root itself.- Return type:
- Returns:
A
importlib.resources.abc.Traversablethat callers may read viaread_text/read_bytes/openor iterate viaiterdir. Useas_path()when a real on-diskpathlib.Pathis required.
- bundled_path(*parts)[source]¶
Return a process-lifetime
pathlib.Pathfor a bundled subtree.Suitable for module-level Settings field defaults that need a real on-disk path at import time. The underlying
as_filecontext is entered into a module-levelcontextlib.ExitStackthat is closed at interpreter exit. Under the supported install modes (editable hatchling, built wheel) the materialisation is a no-op:importlib.resources.files("aeat")resolves to a real on-disk directory andas_filereturns the path unchanged.- Parameters:
*parts (
str) – Path segments joined under the bundled data root.- Return type:
Path- Returns:
A
pathlib.Pathwhose lifetime spans the running process. Callers MUST treat the path as read-only.
- as_path(node)[source]¶
Materialise
nodeas a real on-disk path for the lifetime of the context.importlib.resources.as_fileextracts the resource to a temporary location when the underlying loader does not already expose a filesystem path. Under an editable install (hatchling force-include against the source tree) the materialised path is the in-tree location with no copy.- Parameters:
node (
Traversable) – A Traversable returned bypackaged_data()(or a descendant obtained viajoinpath).- Yields:
A
pathlib.Paththat is valid only inside thewithblock. Callers MUST NOT retain the path beyond the context manager’s exit.- Return type:
Iterator[Path]
- resolve_companion_binary(*parts)[source]¶
Resolve a corpus binary from the optional
aeat_datacompanion alone.- Parameters:
*parts (
str) – Segments under the companion’s mirrored_dataroot (e.g."corpus", "manuals", "renta", "2024", "source.pdf").- Return type:
Path|None- Returns:
A read-only
pathlib.Pathvalid for the process lifetime when the companion is installed and carries the binary, elseNone. The companion mirrorsaeat/_data, so the segments are identical to the onespackaged_data()takes.
- resolve_corpus_binary(*parts)[source]¶
Resolve a bundled corpus binary, the
aeattree first then theaeat_datacompanion.partsare the segments under_data(e.g."corpus", "aeat_official", "disenos_registro", "modelo_100", "files", "dr.xlsx"). The slimaeatwheel excludes_data/corpus/**/*.{pdf,xls,xlsx}; the optionalaeat_datacompanion carries exactly those binaries under mirrored paths. This is the singleimportlib.resourcesseam that unifies the full-checkout read (binary in theaeattree) and the split-install read (binary in the companion).- Return type:
Path|None- Returns:
A read-only
pathlib.Pathvalid for the process lifetime when the binary is present under either root, elseNonewhen it resolves under neither.- Parameters:
parts (str)