transport_data.store.UnionStore¶
- class transport_data.store.UnionStore(config: transport_data.config.Config)[source]¶
Bases:
UnionStoreA store that maps between a
LocalStoreandRegistry.This class extends
dsss.store.UnionStorewith the following behaviour:The sub-stores are initialized from an instance of
Config.assign_version()andget()have extended behaviour. See the documentation of each method.Additional methods
clone()andadd_to_registry().
- __init__(config: transport_data.config.Config) None¶
Initialize the store instance.
Subclasses must call this parent class method to initialize hooks.
- Parameters:
hook – Hooks for the instance. Mapping from
hook_idsto either single callables, or iterables of callables.
Methods
__init__(config)Initialize the store instance.
add_to_registry(urn)Copy data for urn from
LocalStoreto theRegistry.assign_version(obj, **kwargs)Assign a version to obj subsequent to any existing versions.
clone()Clone the underlying
Registry.delete(key)Delete an object given its key.
get(key)Return an object given its key.
get_store_id(key)Return the ID of the store that should be used for obj.
invoke_hooks(kind, *args, **kwargs)Invoke each callable in
hookwithhook_idkind.Iterate over stored keys.
key(obj)Construct a key for obj.
list([klass, maintainer, id, version])List matching keys.
list_versions(klass, maintainer, id)Return all versions of a
MaintainableArtefact.resolve(obj[, attr])Resolve an external reference in a named attr of obj.
set(obj)Store obj and return its key.
update(obj)Update obj and return its key.
update_from(obj, **kwargs)Update the Store from another obj.
Attributes
IDs of hooks.
Mapping from store IDs to instances of
Store.Mapping from maintainer IDs to keys of
store.ID of the default
store.Mapping from
hook_idsto lists of hooks.- assign_version(obj, **kwargs) None¶
Assign a version to obj subsequent to any existing versions.
See also
- clone()¶
Clone the underlying
Registry.Temporary version to work around khaeru/dsss#19. This is identical to
dsss.store.GitStore.clone(), except only certain paths are checked out.
- get(key: str)¶
Return an object given its key.
Compared to the parent class, this implementation:
Expands key from a partial URN (e.g. “AgencyScheme=TDCI:TDCI(1.0.0)”) to a full URN.
Handles key that is a partial URN without a specific version, e.g. “AgencyScheme=TDCI:TDCI”. In this case, the greatest version of the referenced artefact is returned.
- hook: MutableMapping[str, List[Callable]]¶
Mapping from
hook_idsto lists of hooks. Hooks are per-instance.
- iter_keys()¶
Iterate over stored keys.
The keys are not ordered.
- key(obj) str¶
Construct a key for obj.
Supported obj classes include:
MaintainableArtefact.Example:
"urn:sdmx:org.sdmx.infomodel.codelist.Codelist=FOO:CL(1.0)"The key is the full
IdentifiableArtefact.urn.BaseDataSet,BaseMetadataSetExample:
"data-FOO:DSD_ID-adaa503c71ac9574"The key consists of:
"data-"or"metadata-", based on the class of obj;the
IdentifiableArtefact.idof the maintainer of either (a) theDataflowthat describes obj or if not defined (b) of theDataStructurethat structures obj;the ID of the (Meta)Dataflow or (b) (Meta)DataStructure itself; and
a hash of the
Observationkeys.
- list(klass: type | None = None, maintainer: str | None = None, id: str | None = None, version: str | None = None) List[str]¶
List matching keys.
Only keys that match the given parameters (if any) are returned.
- Parameters:
klass (
AnnotableArtefact) – Class of artefact.maintainer – ID of the maintainer of an artefact or its (meta)dataflow.
id – ID of an artefact or its (meta)dataflow.
version – Version of an artefact.
- list_versions(klass: type, maintainer: str, id: str) Tuple[str, ...]¶
Return all versions of a
MaintainableArtefact.The klass, maintainer, and id arguments are the same as for
list().
- maintainer_store: MutableMapping[str, str]¶
Mapping from maintainer IDs to keys of
store.
- resolve(obj, attr: str | None = None) MaintainableArtefact¶
Resolve an external reference in a named attr of obj.
- update(obj)¶
Update obj and return its key.
- update_from(obj: Store, **kwargs) None¶
Update the Store from another obj.
- Parameters:
obj –
Any of:
pathlib.Pathof an.xmlfile or directory —the given file, or all.xmlfiles in the directory and any subdirectories, are read and their contents added.another
Storeinstance —all contents of the other store are added.a
DataMessage—allBaseDataSetin the message are read and stored.a
StructureMessage—all SDMX structures in the message are read and stored.
ignore (optional) – if obj is a path, ignore is an optional iterable of callables. Each of the callables in ignore is applied to every file path to be read; if the any of them returns
True, the file is skipped.
- Raises:
NotImplementedError – for any obj other than the above.