spacr.example_data¶
Download, validate, and cache the optional example-screen data.
The example CSV files are distributed as release assets rather than package data. They are downloaded only when requested, validated against the bundled manifest, and reused from the user’s cache on subsequent runs. This module has no Qt dependency and can also be used from scripts.
Exceptions¶
Raised when the example data cannot be downloaded or validated. |
Classes¶
Paths and download status for a prepared example screen. |
Functions¶
|
Return the directory used to cache example-screen files. |
|
The manifest entries for one |
|
Prepare the example screen, downloading only missing files. |
|
Return whether a file matches one manifest entry. |
|
Return manifest entries absent or invalid in |
|
Return the total expected size of the selected manifest entries. |
Module Contents¶
- exception spacr.example_data.ExampleDataError[source]¶
Bases:
RuntimeErrorRaised when the example data cannot be downloaded or validated.
Initialize self. See help(type(self)) for accurate signature.
- class spacr.example_data.Fetched[source]¶
Paths and download status for a prepared example screen.
- Parameters:
- spacr.example_data.cache_folder() str[source]¶
Return the directory used to cache example-screen files.
SPACR_EXAMPLE_DATAoverrides the location. Otherwise the function usesXDG_CACHE_HOMEor the platform-neutral~/.cachefallback.
- spacr.example_data.entries_of_kind(kind: str | None = None) List[dict][source]¶
The manifest entries for one
kind, or all of them.- Parameters:
kind –
"counts","scores", orNonefor everything.- Raises:
ValueError – for a kind the manifest does not contain, rather than returning an empty list – a typo would otherwise download nothing and report success.
- spacr.example_data.fetch(folder=None, *, progress: Callable | None = None, cancelled: Callable | None = None, download: bool = True, kind: str | None = None) Fetched[source]¶
Prepare the example screen, downloading only missing files.
- Parameters:
folder (path-like, optional) – Cache directory. The standard example cache is used when omitted.
progress (callable, optional) – Called as
progress(name, received_bytes, total_bytes)while each file downloads.cancelled (callable, optional) – Zero-argument callback. A true result cancels the active download.
download (bool, default=True) – If false, require every file to be present in the cache and do not use the network.
- Returns:
Fetched – Validated count and score paths plus download status.
- Raises:
ExampleDataError – If a file cannot be downloaded, validation fails, the operation is cancelled, or downloading is disabled while files are missing.
- spacr.example_data.is_whole(path, entry) bool[source]¶
Return whether a file matches one manifest entry.
- Parameters:
path – file whose size and SHA-256 digest are to be checked.
entry – manifest mapping containing the expected
bytesandsha256values.
The inexpensive size check runs before the SHA-256 digest is calculated.
- spacr.example_data.missing(folder=None, kind: str | None = None) List[dict][source]¶
Return manifest entries absent or invalid in
folder.- Parameters:
kind – restrict to one kind. Regression can fetch its counts and its scores separately, because a user checking one of them should not wait for the other.