clabe.checks ¶
Reusable checks: plain functions that raise, with a readable message, when something is wrong.
A check is any function returning nothing and raising when its condition does not hold. Like a step, it takes
what it needs by parameter name — rig, session, launcher or any other step's output — so the same
check runs inside a workflow and outside one:
from clabe import checks, steps
rig_ready = [
checks.free_space(200e9), # on the rig's data drive
checks.exists(r"\\allen\aind\scratch"), # the share data is copied to
checks.that(lambda rig: rig.cameras, "The rig has no cameras."),
]
wf.step(steps.preflight(*rig_ready)) # in a workflow: one step running them all
checks.run(*rig_ready, rig=rig) # anywhere else
Every check runs, so one failure lists everything that is wrong (see ChecksFailed). Write your own as plain
functions and keep them in a module of your package, next to your steps, for others to import.
ChecksFailed ¶
Bases: RuntimeError
One or more checks failed. Its message lists each failure; failures holds (check name, error).
Source code in src/clabe/checks.py
free_space ¶
Fails when the drive holding directory has less than minimum_bytes free.
The directory need not exist yet: the drive is the one of its nearest existing parent, so mounted folders and network shares are measured where the data will actually go.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimum_bytes
|
float
|
Free space required. |
required |
directory
|
PathSource | None
|
Where the data goes: a path, or a function of the |
None
|
Source code in src/clabe/checks.py
exists ¶
exists(path: PathSource) -> Callable[..., None]
Fails when path (a file, a directory or a network share) does not exist or cannot be reached.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
PathSource
|
The path, or a function of the |
required |
Source code in src/clabe/checks.py
that ¶
that(
condition: Callable[..., Any],
message: str,
*,
name: str | None = None,
) -> Callable[..., None]
A check from a predicate: fails with message when condition returns something false.
The check takes the same parameters as condition, so that(lambda rig: rig.cameras, "...") gets the rig.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
Callable[..., Any]
|
The predicate. |
required |
message
|
str
|
The failure message. |
required |
name
|
str | None
|
The check's name; by default the predicate's. |
None
|
Source code in src/clabe/checks.py
inputs ¶
The names the checks take, in order and without repeats: what run (or a step running them) must be given.
Parameters with a default are left to their default.
Source code in src/clabe/checks.py
run ¶
Runs every check, each with the values it takes, and raises ChecksFailed if any failed.
A check asking the workflow to go back or abort (GoBack, Abort) does so at once.
Raises:
| Type | Description |
|---|---|
ChecksFailed
|
Listing every check that failed. |
TypeError
|
When a check takes a value that was not given. |