dsss.store.GitStore#

class dsss.store.GitStore(path: Path, remote_url: str | None = None, clone: bool = False, **kwargs)#

Bases: StructuredFileStore

A store that uses an underlying Git repository.

__init__(path: Path, remote_url: str | None = None, clone: bool = False, **kwargs) None#

Initialize the store instance.

Subclasses must call this parent class method to initialize hooks.

Parameters#

hook :

Hooks for the instance. Mapping from hook_ids to either single callables, or iterables of callables.

Methods

__init__(path[, remote_url, clone])

Initialize the store instance.

assign_version(obj, **kwargs)

Assign a version to obj subsequent to any existing versions.

clone()

Clone the repository indicated by remote_url.

delete(key)

Delete an object given its key.

get(key)

Return an object given its key.

invoke_hooks(kind, *args, **kwargs)

Invoke each callable in hook with hook_id kind.

iter_keys()

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.

path_for(obj, key)

Construct the path to the file to be written for obj, or read for key.

read_message(path)

Read a sdmx.message.Message from path and return its contents.

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.

write_message(obj, path)

Write obj to an SDMX-ML message at path.

Attributes

hook_ids

IDs of hooks.

ignore

Expressions giving file paths to ignore.

remote_url

URL of a remote Git repository to mirror.

repo

git.Repo object.

path

Storage location.

hook

Mapping from hook_ids to lists of hooks.

assign_version(obj, **kwargs) None#

Assign a version to obj subsequent to any existing versions.

See also#

sdmx.model.version.increment

clone()#

Clone the repository indicated by remote_url.

delete(key)#

Delete an object given its key.

Raises#

KeyError

If the object does not exist.

get(key: str)#

Return an object given its key.

Raises#

KeyError

If the object does not exist.

hook: MutableMapping[str, List[Callable]]#

Mapping from hook_ids to lists of hooks. Hooks are per-instance.

hook_ids: Tuple[str, ...] = ('before set',)#

IDs of hooks. Subclasses may extend this tuple.

ignore: Set[Callable[[Path], bool]] = {<function GitStore.<lambda>>}#

Expressions giving file paths to ignore.

invoke_hooks(kind: str, *args, **kwargs) None#

Invoke each callable in hook with hook_id kind.

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, BaseMetadataSet

Example: "data-FOO:DSD_ID-adaa503c71ac9574"

The key consists of:

  • "data-" or "metadata-", based on the class of obj;

  • the IdentifiableArtefact.id of the maintainer of either (a) the Dataflow that describes obj or if not defined (b) of the DataStructure that structures obj;

  • the ID of the (Meta)Dataflow or (b) (Meta)DataStructure itself; and

  • a hash of the Observation keys.

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#

klassAnnotableArtefact

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().

path: Path#

Storage location.

path_for(obj, key) Path#

Construct the path to the file to be written for obj, or read for key.

read_message(path: Path) MaintainableArtefact | BaseDataSet | BaseMetadataSet#

Read a sdmx.message.Message from path and return its contents.

remote_url: str | None = None#

URL of a remote Git repository to mirror.

repo: git.Repo#

git.Repo object.

resolve(obj, attr: str | None = None) MaintainableArtefact#

Resolve an external reference in a named attr of obj.

set(obj)#

Store obj and return its key.

If obj exists, KeyError is raised.

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.Path of an .xml file or directory —the given file, or all .xml files in the directory and any subdirectories, are read and their contents added.

  • another Store instance —all contents of the other store are added.

  • a DataMessage —all BaseDataSet in the message are read and stored.

  • a StructureMessage —all SDMX structures in the message are read and stored.

Other Parameters#

ignoreoptional

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.

write_message(obj, path)#

Write obj to an SDMX-ML message at path.