Pinned data¶
data
¶
Data files of an experiment: pinned content hashes and readers.
A data clause names a file and pins its content hash. The pin is part of
the experiment's hash, so the hash of an experiment is known without reading
its data; reading checks the file against the pin, and a file whose content
does not match is refused, as an import with a mismatched integrity check is
refused in Dhall. A file is read by the reader registered for its suffix
(register_reader); JSON and CSV readers are built in.
PIN_ALGORITHM
module-attribute
¶
The hash algorithm a data pin names: BLAKE3, the digest every content identity of the language is built from.
DataReader
¶
DataReader = Callable[[bytes], JsonValue]
Reads a data file's bytes as a JSON-shaped value.
file_digest
¶
The digest a data pin records for a file's bytes.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
The file's content.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Its 64-character lowercase hexadecimal BLAKE3 digest. |
Source code in src/quivers/experiments/data.py
render_pin
¶
The pin to write for a digest.
| PARAMETER | DESCRIPTION |
|---|---|
digest
|
A BLAKE3 digest.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
|
Source code in src/quivers/experiments/data.py
register_reader
¶
register_reader(suffix: str, reader: DataReader) -> None
Teach experiments to read data files with another suffix.
| PARAMETER | DESCRIPTION |
|---|---|
suffix
|
The file suffix, such as
TYPE:
|
reader
|
Reads a file's bytes as a JSON-shaped value (numbers, strings, Booleans, lists, and string-keyed objects).
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a reader for the suffix is already registered. |
Source code in src/quivers/experiments/data.py
read_pinned
¶
read_pinned(path: Path, pin: ContentPin | None, *, origin: str, line: int, column: int) -> tuple[str, JsonValue]
Read a pinned data file, checking its content hash.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The file.
TYPE:
|
pin
|
The pin written in the experiment.
TYPE:
|
origin
|
The experiment's file, for the refusal's location.
TYPE:
|
line
|
The clause's line.
TYPE:
|
column
|
The clause's column.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, JsonValue]
|
The file's digest and its value. |
| RAISES | DESCRIPTION |
|---|---|
ExperimentError
|
With code |
Source code in src/quivers/experiments/data.py
check_pin
¶
check_pin(path: Path, pin: ContentPin | None, digest: str, *, origin: str, line: int, column: int) -> None
Refuse a file whose digest is not the one pinned.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
The file.
TYPE:
|
pin
|
The pin written in the experiment.
TYPE:
|
digest
|
The file's BLAKE3 digest.
TYPE:
|
origin
|
The experiment's file.
TYPE:
|
line
|
The clause's line.
TYPE:
|
column
|
The clause's column.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ExperimentError
|
With code |