annie.dataset.datasets¶
Dataset config files: save, load, and discover a SourceRegistry (service).
A config is a small JSON file describing a dataset as a list of data sources, so a set of folders/CSVs can be loaded in one click instead of re-picking them every restart. Paths may be relative (resolved against the config file’s directory, so configs that reference the bundled examples travel with the repo) or absolute.
When running from a source checkout, example configs under data/config/ are
auto-discovered and listed in the Dataset tab dropdown. When installed from PyPI
the data/ directory is absent and discovery returns an empty list silently;
users load configs via the file picker or save their own.
Attributes¶
File under |
Functions¶
|
Return the bundled |
|
Return the source-checkout config directory ( |
|
List |
|
Return a config's display name (its |
|
Load a config file into a |
|
Serialise a registry to a config dict. |
|
Write a registry to a config file as JSON. |
|
Record |
|
Return the config remembered by |
Module Contents¶
- annie.dataset.datasets.repo_data_dir() pathlib.Path[source]¶
Return the bundled
datadirectory.Prefers the explicit
ANNIE_DATA_DIRoverride (settings.data_dir), which non-editable installs (Docker, PyPI) need because the package lives insite-packagesanddatadoes not. Otherwise falls back to three levels up from this file, which is valid only from agit clone. Callers must handle a non-existent path gracefully.
- annie.dataset.datasets.bundled_config_dir() pathlib.Path[source]¶
Return the source-checkout config directory (
data/config).May not exist when Annie is installed from PyPI.
- annie.dataset.datasets.discover_configs(directory: str | pathlib.Path | None = None) list[pathlib.Path][source]¶
List
*.jsonconfig files for the Dataset tab dropdown.Returns an empty list silently when a directory does not exist, so PyPI installs degrade gracefully without bundled examples.
With no argument this scans the bundled config directory and, when
ANNIE_CONFIG_DIRis set (e.g. in Docker to a persistent volume path), appends that directory’s configs deduplicated by stem. When an explicitdirectoryis passed it is treated as the sole search root — theANNIE_CONFIG_DIRmerge is not applied — so callers get exactly what they ask for.- Parameters:
directory – Explicit directory to scan exclusively; defaults to the bundled dir merged with
ANNIE_CONFIG_DIR.- Returns:
Sorted config file paths, or
[]if the directories are absent.
- annie.dataset.datasets.config_name(path: str | pathlib.Path) str[source]¶
Return a config’s display name (its
namefield, or the file stem).- Parameters:
path – The config file.
- Returns:
The configured name, or the filename stem on any read/parse error.
- annie.dataset.datasets.load_config(path: str | pathlib.Path) tuple[str, annie.dataset.sources.SourceRegistry, pathlib.Path | None][source]¶
Load a config file into a
(name, registry, db_path)triple.Relative source paths — and the optional
dbpath — are resolved against the config file’s directory. Column types for CSV sources are auto-detected from a 500-row sample when not declared in the config.- Parameters:
path – The config file to load.
- Returns:
The dataset name, a populated
SourceRegistry, and an optionalPathto a pre-configured review database (Noneif the config has no"db"field).- Raises:
ValueError – If the JSON is malformed or a source kind is unknown.
- annie.dataset.datasets.to_config_dict(registry: annie.dataset.sources.SourceRegistry, name: str, *, relative_to: str | pathlib.Path | None = None, db_path: str | pathlib.Path | None = None) dict[source]¶
Serialise a registry to a config dict.
- Parameters:
registry – The sources to serialise.
name – The dataset name to store.
relative_to – If given, store paths relative to this directory where possible.
db_path – Optional path to a review database to embed in the config so that loading it re-opens the same DB automatically.
- Returns:
A JSON-serialisable config dict.
- annie.dataset.datasets.save_config(path: str | pathlib.Path, registry: annie.dataset.sources.SourceRegistry, name: str, *, relative_to: str | pathlib.Path | None = None, db_path: str | pathlib.Path | None = None) pathlib.Path[source]¶
Write a registry to a config file as JSON.
- Parameters:
path – Destination
.jsonpath.registry – The sources to save.
name – The dataset name to store.
relative_to – If given, store paths relative to this directory where possible.
db_path – Optional review-database path to embed in the config.
- Returns:
The path written.
- annie.dataset.datasets.LAST_CONFIG_FILENAME = 'last_config.json'¶
File under
ANNIE_HOMEremembering the config most recently loaded or saved.
- annie.dataset.datasets.remember_last_config(path: str | pathlib.Path) None[source]¶
Record
pathas the config to reopen on the next start.- Parameters:
path – The config file just loaded or saved.
- annie.dataset.datasets.last_config() pathlib.Path | None[source]¶
Return the config remembered by
remember_last_config(), if it still exists.A config that is gone from its remembered path is still found when it moved together with the whole Annie home (e.g. the Windows installer moving your work to a new data folder): the same file name is looked up in the config folder.
- Returns:
The config path, or
Nonewhen nothing is remembered, the pointer file is unreadable, or the config has since been deleted or moved elsewhere.