clabe.stores ¶
Candidate
dataclass
¶
CompositeStore ¶
Bases: StoreBase
Routes each kind to a backend by record name, falling back to a default store.
This is what composition buys over subclassing: a deployment keeping rigs and tasks on a network share but trainer state in Dataverse is a routing table, not a class.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
Store | None
|
Serves any kind not named in |
None
|
routes
|
Mapping[str, Store] | None
|
Maps a |
None
|
Source code in src/clabe/stores/_base.py
resolve ¶
resolve(
kind: KindLike[T],
*,
scope: Scope | None = None,
pick_kwargs: PickRequestKwargs | None = None,
) -> T
Delegates to the routed backend, so its own presentation is used.
Source code in src/clabe/stores/_base.py
write ¶
scoped ¶
scoped(**scope: str) -> CompositeStore
Returns a composite whose every backend is narrowed by the given scope.
Source code in src/clabe/stores/_base.py
Kind ¶
Kind(
model: type[T],
name: str | None = None,
*,
validators: Callable[[T], T]
| Iterable[Callable[[T], T]]
| None = None,
)
Bases: Generic[T]
A record name bound to the pydantic model that parses it.
The name routes the record to a backend and determines its storage layout; the model types the return value of every store call made with this kind.
Canonical kinds should be built through from_rig, from_task,
from_session or from_trainer_state, which fix the framework
name. The bare constructor derives the name from the model class instead,
so Kind(AindVrForagingRig) is named "aind_vr_foraging_rig", not
"rig" -- it is for custom records only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[T]
|
The pydantic model records of this kind deserialize to. |
required |
name
|
str | None
|
The record name. Defaults to the snake-cased model class name. |
None
|
validators
|
Callable[[T], T] | Iterable[Callable[[T], T]] | None
|
One callable, an iterable of callables, or |
None
|
Source code in src/clabe/stores/_base.py
adapter
cached
property
¶
Serializes and parses records of this kind. Also covers models that are not BaseModel.
from_rig
staticmethod
¶
from_rig(
model: type[TRig],
*,
validators: Callable[[TRig], TRig]
| Iterable[Callable[[TRig], TRig]]
| None = validators,
) -> Kind[TRig]
Builds the canonical "rig" kind for a rig model.
Source code in src/clabe/stores/_base.py
from_task
staticmethod
¶
Store ¶
Bases: Protocol
Reads, resolves and writes records of a given Kind.
Which kinds a store actually serves is a deployment fact, not a type-level one: an unsupported kind raises when the call is made.
resolve ¶
resolve(
kind: KindLike[T],
*,
scope: Scope | None = None,
pick_kwargs: PickRequestKwargs | None = None,
) -> T
Selects a single record, prompting the user when the choice is ambiguous.
write ¶
Persists a record. Whether that overwrites, versions or appends is the store's contract.
StoreBase ¶
Bases: ABC
Base for stores, supplying scope narrowing and the default resolution policy.
Subclasses implement _candidates and write, and may override
resolve when their backend affords a better presentation than a flat
pick list.
Source code in src/clabe/stores/_base.py
scoped ¶
Returns a view sharing this store's data, narrowed by the given scope.
The view is the same concrete store type, so narrowing never loses backend-specific typing.
Source code in src/clabe/stores/_base.py
write
abstractmethod
¶
list ¶
list(
kind: KindLike[T], *, scope: Scope | None = None
) -> Sequence[T]
Returns every record of this kind in scope, validated but unprompted.
Source code in src/clabe/stores/_base.py
resolve ¶
resolve(
kind: KindLike[T],
*,
scope: Scope | None = None,
pick_kwargs: PickRequestKwargs | None = None,
) -> T
Selects a single record: raises on none, auto-selects a lone candidate, prompts otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
KindLike[T]
|
The kind of record to resolve. |
required |
scope
|
Scope | None
|
Narrows which records are considered. Layered over the store's own scope. |
None
|
pick_kwargs
|
PickRequestKwargs | None
|
Optional overrides for the |
None
|
Raises:
| Type | Description |
|---|---|
LookupError
|
If no record of this kind exists in scope, or the user declined to pick one. |
NoSessionError
|
If a choice must be made and nothing can ask the user. |
Source code in src/clabe/stores/_base.py
DefaultLayout ¶
The config library tree as it exists on the shared drive today.
Rig/<computer_name>/*.json, Task/*.json and
Subjects/<subject>/<kind>.json. Tasks read from the subject folder first
and fall back to the shared library, which is the ordered scope chain that
replaces the nested lookup the picker used to do inline.
Kinds other than rig and task are per-subject state, living beside
the subject's task; with no subject in scope they sit at the library root,
which is what makes a one-off store pointed at a session directory work.
read ¶
Returns the glob patterns for this kind, subject folder before shared library.
Source code in src/clabe/stores/_local.py
write ¶
Returns the single path this kind is written to.
Source code in src/clabe/stores/_local.py
LocalFileStore ¶
LocalFileStore(
root: PathLike | str,
*,
layout: Layout | None = None,
scope: Scope | None = None,
)
Bases: StoreBase
A store over a directory of JSON files, i.e. the config library.
Writes overwrite, and create the directories they need. Files that fail to parse are skipped with a warning rather than failing the whole listing.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
PathLike | str
|
The config library directory. |
required |
layout
|
Layout | None
|
Maps kinds onto paths within |
None
|
scope
|
Scope | None
|
Initial scope. |
None
|
Source code in src/clabe/stores/_local.py
scoped ¶
Returns a view sharing this store's data, narrowed by the given scope.
The view is the same concrete store type, so narrowing never loses backend-specific typing.
Source code in src/clabe/stores/_base.py
list ¶
list(
kind: KindLike[T], *, scope: Scope | None = None
) -> Sequence[T]
Returns every record of this kind in scope, validated but unprompted.
Source code in src/clabe/stores/_base.py
resolve ¶
resolve(
kind: KindLike[T],
*,
scope: Scope | None = None,
pick_kwargs: PickRequestKwargs | None = None,
) -> T
Selects a single record: raises on none, auto-selects a lone candidate, prompts otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
KindLike[T]
|
The kind of record to resolve. |
required |
scope
|
Scope | None
|
Narrows which records are considered. Layered over the store's own scope. |
None
|
pick_kwargs
|
PickRequestKwargs | None
|
Optional overrides for the |
None
|
Raises:
| Type | Description |
|---|---|
LookupError
|
If no record of this kind exists in scope, or the user declined to pick one. |
NoSessionError
|
If a choice must be made and nothing can ask the user. |
Source code in src/clabe/stores/_base.py
write ¶
Overwrites the file this kind maps to, creating parent directories.
Source code in src/clabe/stores/_local.py
MemoryStore ¶
Bases: StoreBase
A store holding records in memory, for tests and for assembling records in-process.
Writes append, as Dataverse does, so several records of one kind can be offered as candidates. A record is visible to a read whose scope agrees with every narrowing the record was written under, so a record written unscoped is library-wide.
Source code in src/clabe/stores/_memory.py
scoped ¶
Returns a view sharing this store's data, narrowed by the given scope.
The view is the same concrete store type, so narrowing never loses backend-specific typing.
Source code in src/clabe/stores/_base.py
list ¶
list(
kind: KindLike[T], *, scope: Scope | None = None
) -> Sequence[T]
Returns every record of this kind in scope, validated but unprompted.
Source code in src/clabe/stores/_base.py
resolve ¶
resolve(
kind: KindLike[T],
*,
scope: Scope | None = None,
pick_kwargs: PickRequestKwargs | None = None,
) -> T
Selects a single record: raises on none, auto-selects a lone candidate, prompts otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kind
|
KindLike[T]
|
The kind of record to resolve. |
required |
scope
|
Scope | None
|
Narrows which records are considered. Layered over the store's own scope. |
None
|
pick_kwargs
|
PickRequestKwargs | None
|
Optional overrides for the |
None
|
Raises:
| Type | Description |
|---|---|
LookupError
|
If no record of this kind exists in scope, or the user declined to pick one. |
NoSessionError
|
If a choice must be made and nothing can ask the user. |
Source code in src/clabe/stores/_base.py
write ¶
Appends a record, so repeated writes accumulate as candidates.