-
MetaSpec — Define a key mapping and transform functions.
comicbox.formats.base.transforms.spec¶
source module comicbox.formats.base.transforms.spec
Transform maps.
A MetaSpec maps destination keypaths to source keypaths. _create_specs compiles a set of them into one glom spec in two phases, and refuses to compile a set whose declarations contradict each other.
Destination keyspace: a compile owns its destinations. Two metaspecs claiming the same keypath, or one claiming a keypath nested inside another’s, raise at import. glom’s assign used to resolve those silently – the later mapping won the value at the earlier one’s slot, and a nested pair either lost the whole subtree or was set as an attribute of the enclosing spec and never reached the output.
Scope channel: a metaspec with assign_global publishes its spec function’s result into glom’s per call globals, and other metaspecs read it back by naming S.globals.comicbox.<key> among their sources. glom evaluates a compiled dict in key insertion order, so phase one compiles the producers and phase two everything else. Declaration order no longer decides whether a read resolves. Only one producer per compile: a second publish replaces the whole scope mapping. Readers still supply their own default, because publishing happens at runtime over data that may hold nothing; the compile only proves a producer exists.
Classes
Functions
-
create_specs_to_comicbox — Create to comicbox specs.
-
create_specs_from_comicbox — Create from comicbox specs.
Define a key mapping and transform functions.
source create_specs_to_comicbox(*metaspecs: MetaSpec, format_root_keypath: str = ‘’, comicbox_root_keypath: str = ROOT_KEYPATH) → MappingProxyType[str, dict[str, Coalesce] | Coalesce]
Create to comicbox specs.
source create_specs_from_comicbox(*metaspecs: MetaSpec, format_root_keypath: str = ‘’, comicbox_root_keypath: str = ROOT_KEYPATH) → MappingProxyType[str, dict[str, dict[str, Coalesce]] | dict[str, Coalesce] | Coalesce]
Create from comicbox specs.