cadrumo.core.resources.bundled_data module¶
Single boundary for reading bundled corpus and registry data.
Bundled trees live at cadrumo/_data/corpus/... and
cadrumo/_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 repo-root walk. Use bundled_path() when a
process-lifetime Path is required, and as_path() for a
scoped materialised path. The data-root anchor is reserved for var/
operator outputs in cadrumo.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 command-bearing cadrumo wheel and shipped in two mandatory
cadrumo_data companion distributions whose joined layout mirrors
cadrumo/_data. resolve_corpus_binary() is the single
importlib.resources seam that resolves such a binary from the cadrumo
tree first and then the companion namespace, so a full checkout and an installed
three-wheel cohort read a corpus binary uniformly. A missing companion remains
a not-present signal (None) at this low-level resource boundary; the
catalogue integrity boundary turns that signal into a hard failure.
Because the split is by file SUFFIX rather than by directory, a corpus
directory is a single logical tree whose members can materialise under
different installed roots: a design workbook resolves under cadrumo_data
while the hand-authored declarations that annotate it stay under cadrumo.
A reader that reaches a neighbouring file with pathlib.Path.with_name()
therefore sees only the root its starting file happened to come from.
bundled_data_roots() and resolve_data_root_copies() are the seam
that spans them, so a neighbour is located by its position in the logical tree
rather than by which distribution happens to carry the file next to it.
- packaged_data(*parts)[source]¶
Return a Traversable rooted at
cadrumo/_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("cadrumo")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:
Generator[Path]
- resolve_companion_binary(*parts)[source]¶
Resolve a corpus binary from the mandatory
cadrumo_datanamespace.- 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 joined companion namespace carries the binary, elseNone. The namespace mirrorscadrumo/_data, so the segments are identical to the onespackaged_data()takes.
- resolve_corpus_binary(*parts)[source]¶
Resolve a bundled corpus binary, the
cadrumotree first then thecadrumo_datacompanion.partsare the segments under_data(e.g."corpus", "aeat_official", "disenos_registro", "modelo_100", "files", "dr.xlsx"). The command-bearing Cadrumo wheel excludes_data/corpus/**/*.{pdf,xls,xlsx}; the mandatorycadrumo_datanamespace carries exactly those binaries under mirrored paths. This is the singleimportlib.resourcesseam that unifies the full-checkout read (binary in thecadrumotree) and the installed-cohort read (binary in a companion distribution).- 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)
- bundled_data_roots()[source]¶
Return every installed root the bundled
_datatree materialises under.The
cadrumotree comes first and is always present; each installedcadrumo_dataportion follows. Together they are the roots a single logical_data-relative path may resolve under, which is what makes the suffix-partitioned corpus one tree rather than three.
- resolve_data_root_copies(path)[source]¶
Return every existing copy of
pathacross the bundled_dataroots.pathis an ordinary filesystem path a caller computed by navigating from some other bundled file – a sibling annotation, a per-directory declaration. Whichever rootpathcurrently sits under, the same_data-relative position is checked under every other root, so a file and its neighbour are found together even when the distribution split placed them apart.A
pathunder no bundled root is left alone and answered from the filesystem: a temporary fixture or an operator-supplied file has no position in the logical tree, and inventing one for it would be a claim this seam cannot support.- Parameters:
path (
Path) – The location to resolve, expressed in any one root’s coordinates.- Return type:
- Returns:
Every existing copy, in
bundled_data_roots()order, so the first entry is thecadrumotree’s copy whenever it has one. Empty when the file exists under no root. More than one entry means the same logical file is published by more than one distribution, which callers that cannot tolerate a silent winner must adjudicate.