Skip to content

Commit fe40ac3

Browse files
committed
Expand docs of .store
1 parent 4ba942e commit fe40ac3

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

doc/index.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,18 @@ The following modules contain *generic* code and utilities usable with (meta)dat
7777
tests
7878
util
7979

80-
- :mod:`.cli`: :doc:`cli`
80+
- :mod:`~transport_data.cli`: :doc:`cli`
8181
- :mod:`.config`: :doc:`config`
8282
- :mod:`.store`: :doc:`store`
8383
- :mod:`.testing`: :doc:`testing`
8484
- :mod:`.tests`: :doc:`tests`
8585
- :mod:`.util`: :doc:`util`
8686

87+
There are also the following top-level objects:
88+
89+
.. autodata:: transport_data.CONFIG
90+
.. autodata:: transport_data.STORE
91+
8792
Indices and tables
8893
==================
8994

doc/store.rst

+50
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,54 @@
11
(Meta)data storage
22
******************
33

4+
:mod:`transport_data.store` provides for storing and handling two kinds of data files:
5+
6+
Local data
7+
Data that exist only on an individual user's system.
8+
These may include:
9+
10+
- Cached files such as those downloaded from particular network locations.
11+
- Temporary or intermediate data files produced or used by other code in :mod:`transport_data` or downstream packages.
12+
13+
These data are handled by an instance of the :class:`.LocalStore` class.
14+
15+
Maintained data
16+
These are data that may be distributed and referenced by other users and SDMX data or structures.
17+
They are handled by an instance of the :class:`.Registry` class.
18+
19+
:data:`transport_data.STORE` is an instance of the :class:`.UnionStore` class, which dispatches operations to :class:`.LocalStore` or :class:`.Registry` according to the maintainer of objects.
20+
All three classes are subclassed of :class:`.BaseStore` and share a common interface.
21+
22+
.. _store-layout:
23+
24+
Formats and layout
25+
==================
26+
27+
- Files are stored in the (configurable) directory indicated by :attr:`.Config.data_path`.
28+
This defaults to the :ref:`platformdirs:api:user data directory`.
29+
For instance, on a Unix/Linux system, the data may be in :file:`$HOME/.local/share/transport-data/`.
30+
31+
- :class:`.LocalStore` files are in a :file:`…/local/` subdirectory.
32+
- :class:`.Registry` files are in a :file:`…/registry/` subdirectory.
33+
34+
- All files are stored as SDMX-ML (XML).
35+
36+
Every SDMX :class:`~sdmx.model.common.MaintainableArtefact` has a `uniform resource name (URN) <https://en.wikipedia.org/wiki/Uniform_Resource_Name>`__ that resembles ``urn:sdmx:org.sdmx.infomodel.codelist.Codelist=TEST:COLOUR(1.2.3)``.
37+
In this example:
38+
39+
- "TEST" is the :attr:`~sdmx.model.common.IdentifiableArtefact.id` of a :class:`~sdmx.model.common.Agency` stored as the :attr:`~sdmx.model.common.MaintainableArtefact.maintainer` attribute.
40+
- "COLOUR" is the ID of the object itself.
41+
- "(1.2.3)" is the :attr:`~sdmx.model.common.VersionableArtefact.version` attribute of a :class:`~sdmx.model.common.VersionableArtefact`.
42+
43+
- Directory and file names include maintainer ID, object class name, and object ID.
44+
For instance, the file :file:`TEST/Codelist_TEST_COLOUR.xml` contains the :class:`~sdmx.model.common.Codelist` with ID "COLOUR" maintained by the agency with ID "TEST".
45+
- Each file contains **only** objects of the class, ID, and maintainer corresponding to its path.
46+
- Each file **may** contain *multiple versions* of objects.
47+
For instance, the file :file:`TEST/Codelist_TEST_COLOUR.xml` may contain objects with the URNs and versions:
48+
49+
- ``urn:sdmx:org.sdmx.infomodel.codelist.Codelist=TEST:COLOUR(1.0.0)`` → version 1.0.0;
50+
- ``urn:sdmx:org.sdmx.infomodel.codelist.Codelist=TEST:COLOUR(1.2.3)`` → version 1.2.3;
51+
- ``urn:sdmx:org.sdmx.infomodel.codelist.Codelist=TEST:COLOUR(1.2.4)`` → version 1.2.4;
52+
- and so on.
53+
454
.. include:: _api/transport_data.store.rst

transport_data/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
log.setLevel(logging.INFO)
99
log.addHandler(logging.StreamHandler(sys.stdout))
1010

11+
#: Global configuration.
1112
CONFIG = Config.read()
13+
14+
#: Global access to data storage.
1215
STORE = UnionStore(CONFIG)

transport_data/config.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
class Config:
1212
"""Common configuration."""
1313

14-
#: Path to the configuration file read, if any
14+
#: Path to the configuration file read, if any.
1515
config_path: Optional[Path] = None
1616

17-
#: Path to a local clone of https://github.com/transport-data/registry.
17+
#: Path for local data. See :ref:`store-layout` for details.
1818
data_path: Path = field(
1919
default_factory=lambda: user_data_path("transport-data", ensure_exists=True)
2020
)
@@ -32,6 +32,7 @@ def _config_path():
3232

3333
@classmethod
3434
def read(cls):
35+
"""Read configuration from file, returning a new instance."""
3536
cp = cls._config_path()
3637
if cp.exists():
3738
with open(cp) as f:
@@ -44,6 +45,7 @@ def read(cls):
4445
return cls(**data)
4546

4647
def write(self):
48+
"""Write configuration to file."""
4749
cp = self._config_path()
4850
if not cp.parent.exists():
4951
print(f"Create {cp.parent}")

transport_data/store.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _maintainer(obj: Union[m.MaintainableArtefact, m.DataSet]) -> m.Agency:
4646
class BaseStore(ABC):
4747
"""A class for file-based storage of SDMX artefacts."""
4848

49+
#: Top level file system path containing stored files.
4950
path: Path
5051

5152
@abstractmethod
@@ -203,7 +204,17 @@ def __init__(self, config) -> None:
203204

204205

205206
class Registry(BaseStore):
206-
"""The transport-data/registry Git repository."""
207+
"""Registry of TDCI-maintained structure information.
208+
209+
Currently these are stored in, and available from, the
210+
`transport-data/registry <https://github.com/transport-data/registry>`_ GitHub
211+
repository. This class handles the interaction with a local clone of that
212+
repository.
213+
214+
In the future, they will be maintained on a full SDMX REST web service, and this
215+
class will handle retrieving from and publishing to that web service, with
216+
appropriate caching etc.
217+
"""
207218

208219
def __init__(self, config) -> None:
209220
self.path = config.data_path.joinpath("registry")
@@ -251,6 +262,7 @@ def write(
251262
class UnionStore(BaseStore):
252263
"""A store that maps between a :class:`.LocalStore` and :class:`.Registry`."""
253264

265+
#: Instances of :class:`.LocalStore` and :class:`.Registry`.
254266
store: Mapping[Literal["local", "registry"], BaseStore]
255267

256268
#: Mapping from maintainer IDs (such as "TEST" or "TDCI") to either "local" or
@@ -294,6 +306,7 @@ def assign_version(
294306
)
295307

296308
def clone(self):
309+
"""Clone the underlying :class:`.Registry`."""
297310
self.store["registry"].clone()
298311

299312

0 commit comments

Comments
 (0)