Skip to content

madbot_cli.checks

Check a deposit file against the schemas the instance publishes, before any write.

madbot checks on write the shared parameters and the credentials of a connection, the settings of a submission and each metadata value. It publishes the schema of each: plan and apply check the file against them first, so that every value madbot would refuse is reported at once, with what it expects, instead of one by one in the middle of an apply.

madbot stays the judge: a format the client cannot check offline, such as an ORCID or a taxon looked up in a referential, is left to madbot.

Credentials never appear in a message: only their keys and the form the plugin expects.

Attributes

NameDescription
CLOSESTHow many close values a message proposes.
FORMATSWhat a format of JSON Schema asks for, in words.
FORMAT_CHECKERThe formats checked offline; madbot checks the others itself.
SHOWN_CHOICESHow many allowed values a message lists, at most.
TYPESWhat a type of JSON Schema asks for, in words.

Classes

NameDescription
CheckErrorThe file gives values madbot would refuse.
SchemasThe schemas and the fields the instance publishes, read once per command.

Functions

NameDescription
checkCheck a deposit file against the schemas the instance publishes.
check_connectionCheck the shared parameters and the credentials of a source or a repository.
check_metadataCheck each metadata value of a submission against the schema of its field.
check_paramsCheck the parameters of a connection against those of its plugin.
check_settingsCheck the settings of a submission to create against those of its repository.
check_submissionCheck the repository, the settings and the metadata of a submission.
check_valueCheck a value against its schema, as madbot does on write.
closestFind the allowed values closest to a value, by their text or their title.
deepestFollow an error of forms to the error of the form closest to the value.
describedDescribe the parameters a plugin expects, with their values.
expectedSay in words what a schema accepts.
expected_acrossSay in words what a part expects, in each form of the object that has it.
explainSay what is wrong with a value and what is expected instead.
key_ofReturn the key a schema address stands for.
listedWrite values in a sentence, cut when they are many.
metadata_valuesList the values of the metadata of a submission, with where they are.
object_partsList the parts of an object a metadata field holds, to write it with its keys.
parametersRead the schemas of the parameters of a plugin, by key.
plugin_hintName the discovery command that describes a plugin.
requireStop when the file gives values madbot would refuse.
unnamed_formSay which part of an object names its form, when the value names none.
unquoted_dateFind a date YAML read from an unquoted value, such as 2026-11-02.
variant_ofChoose the form of a schema a value names by its fixed parts.

CLOSESTattributemodule attribute#

CLOSEST = 3

How many close values a message proposes.

FORMATSattributemodule attribute#

FORMATS = {
  'date': 'a full date, YYYY-MM-DD',
  'date-time': 'a date and a time, YYYY-MM-DDThh:mm:ss',
  'time': 'a time, hh:mm:ss',
  'email': 'an email address'
}

What a format of JSON Schema asks for, in words.

FORMAT_CHECKERattributemodule attribute#

FORMAT_CHECKER = jsonschema.Draft201909Validator.FORMAT_CHECKER

The formats checked offline; madbot checks the others itself.

SHOWN_CHOICESattributemodule attribute#

SHOWN_CHOICES = 5

How many allowed values a message lists, at most.

TYPESattributemodule attribute#

TYPES = {
  'string': 'a text',
  'integer': 'a whole number',
  'number': 'a number',
  'boolean': 'true or false',
  'object': 'an object (key: value)',
  'array': 'a list',
  'null': 'nothing'
}

What a type of JSON Schema asks for, in words.

CheckErrorclass#

class CheckError(errors: list[str])

Bases: MadbotError

The file gives values madbot would refuse.

Attributes

NameTypeDescription
errorslist of strOne message per value, each starting with where it is in the file.

Parameters

NameTypeDescription
errorslist of strOne message per value.

errorsattributeinstance attribute#

errors = errors

Schemasclass#

class Schemas(client: Client)

The schemas and the fields the instance publishes, read once per command.

clientattributeinstance attribute#

client = client

fieldsmethod#

def fields(source: str) -> dict[str, list[dict]]

List the metadata fields of a plugin, by slug.

Parameters

NameTypeDescription
sourcestrThe slug of the plugin.

Returns

dict
The fields of each slug, as the API returns them.

schemamethod#

def schema(url: str) -> dict

Read a schema, its definitions put in place.

Parameters

NameTypeDescription
urlstrIts address, as the API gives it.

Returns

dict
The schema.

checkfunction#

def check(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> list[str]

Check a deposit file against the schemas the instance publishes.

Only what apply would write is checked: a connection madbot holds keeps its parameters, and the metadata of a submission already sent to its repository cannot change.

Parameters

NameTypeDefaultDescription
clientClientrequiredThe client.
stateStaterequiredWhat madbot holds.
manifestManifestrequiredThe deposit file.
environmappingNoneThe environment holding the credentials.

Returns

list of str
One message per value madbot would refuse; empty when there is none.

check_connectionfunction#

def check_connection(schemas: Schemas, plugins: list[dict], spec: Mapping[str, Any], where: str, planned: Mapping, environ: Mapping[str, str] | None = None) -> list[str]

Check the shared parameters and the credentials of a source or a repository.

The shared parameters are checked when the connection is to be created: one madbot holds has them already. The credentials are checked when apply would send them.

Parameters

NameTypeDefaultDescription
schemasSchemasrequiredThe schemas of the instance.
pluginslist of dictrequiredThe plugins of the instance.
specmappingrequiredplugin, shared_params and credentials_env from the file.
wherestrrequiredWhere it is in the file, such as sources.reads.
plannedmappingrequiredThe plan of the connection, with its action and credentials.
environmappingNoneThe environment holding the credentials.

Returns

list of str
One message per error.

check_metadatafunction#

def check_metadata(schemas: Schemas, plugin: Mapping, metadata: Mapping[str, Any], where: str) -> list[str]

Check each metadata value of a submission against the schema of its field.

Parameters

NameTypeDescription
schemasSchemasThe schemas of the instance.
pluginmappingThe plugin of the repository, whose fields the values fill.
metadatamappingThe metadata of the submission in the file.
wherestrThe submission, in the messages.

Returns

list of str
One message per value madbot would find invalid, that YAML read as a date, or given for no field of the repository: madbot would refuse the whole write, and a typo would leave the value unwritten.

check_paramsfunction#

def check_params(known: Mapping[str, Mapping], given: Mapping[str, Any], where: str, plugin: Mapping, *, secret: bool = False) -> list[str]

Check the parameters of a connection against those of its plugin.

Parameters

NameTypeDefaultDescription
knownmappingrequiredThe schema of each parameter of the plugin, by key.
givenmappingrequiredThe parameters of the file, or the credentials.
wherestrrequiredWhere they are, in the messages.
pluginmappingrequiredThe plugin.
secretboolFalseTrue for credentials: no message shows a value.

Returns

list of str
One message per key unknown, missing or of a value madbot refuses.

check_settingsfunction#

def check_settings(schemas: Schemas, plugin: Mapping, settings: Mapping[str, Any], where: str) -> list[str]

Check the settings of a submission to create against those of its repository.

Parameters

NameTypeDescription
schemasSchemasThe schemas of the instance.
pluginmappingThe plugin of the repository.
settingsmappingThe settings of the file.
wherestrWhere they are in the file.

Returns

list of str
One message per setting unknown, missing while mandatory, or of a value madbot refuses.

check_submissionfunction#

def check_submission(schemas: Schemas, state: State, submission: Submission, environ: Mapping[str, str] | None = None) -> list[str]

Check the repository, the settings and the metadata of a submission.

Parameters

NameTypeDefaultDescription
schemasSchemasrequiredThe schemas of the instance.
stateStaterequiredWhat madbot holds.
submissionSubmissionrequiredThe submission.
environmappingNoneThe environment holding the credentials.

Returns

list of str
One message per error.

check_valuefunction#

def check_value(schema: Mapping, value: Any, *, secret: bool = False) -> list[str]

Check a value against its schema, as madbot does on write.

Parameters

NameTypeDefaultDescription
schemamappingrequiredThe JSON Schema, its definitions in place.
valueAnyrequiredThe value.
secretboolFalseTrue for credentials: no message shows the value.

Returns

list of str
What is wrong, empty when the value is valid.

closestfunction#

def closest(value: Any, choices: Iterable[Mapping]) -> list[str]

Find the allowed values closest to a value, by their text or their title.

Parameters

NameTypeDescription
valueAnyThe value given.
choicesiterable of mappingThe allowed values, as madbot_cli.discover.choices_of gives them.

Returns

list of str
At most CLOSEST values, the closest first.

deepestfunction#

def deepest(error: jsonschema.ValidationError) -> jsonschema.ValidationError

Follow an error of forms to the error of the form closest to the value.

Parameters

NameTypeDescription
errorValidationErrorAn error, maybe of oneOf or anyOf.

Returns

ValidationError
The error to explain. An error of forms whose forms are only fixed values stays as it is: its message is the list of values.

describedfunction#

def described(known: Mapping[str, Mapping]) -> str

Describe the parameters a plugin expects, with their values.

Parameters

NameTypeDescription
knownmappingThe schema of each parameter, by key.

Returns

str
Such as url: one of https://a or https://b; token: a text.

expectedfunction#

def expected(schema: Mapping) -> str

Say in words what a schema accepts.

Parameters

NameTypeDescription
schemamappingThe JSON Schema of a value.

Returns

str
Such as one of a or b, a full date, YYYY-MM-DD, or a text.

expected_acrossfunction#

def expected_across(found: list[tuple[str, Mapping]]) -> str

Say in words what a part expects, in each form of the object that has it.

Parameters

NameTypeDescription
foundlist of tupleThe title of each form that has the part (form 2 when it has none), with the schema of the part in it.

Returns

str
What it expects; the fixed values of the forms together, each once, such as one of A or B; or else what each form expects, by its title, the forms that expect the same said together.

explainfunction#

def explain(error: jsonschema.ValidationError, *, secret: bool = False) -> str

Say what is wrong with a value and what is expected instead.

Parameters

NameTypeDefaultDescription
errorValidationErrorrequiredThe error of the value.
secretboolFalseTrue for credentials: the message never shows the value.

Returns

str
The message, starting with the part of the value when it is inside it.

key_offunction#

def key_of(url: str) -> str

Return the key a schema address stands for.

Parameters

NameTypeDescription
urlstrThe address of the schema of a parameter or a setting.

Returns

str
Its last part, which the API builds from the slug.

listedfunction#

def listed(values: Iterable[Any], limit: int = SHOWN_CHOICES) -> str

Write values in a sentence, cut when they are many.

Parameters

NameTypeDefaultDescription
valuesiterablerequiredThe values.
limitintSHOWN_CHOICESHow many are written.

Returns

str
Such as a, b or c, or a, b, c… (12 values).

metadata_valuesfunction#

def metadata_values(metadata: Mapping[str, Any]) -> Iterable[tuple[str, str, Any]]

List the values of the metadata of a submission, with where they are.

Parameters

NameTypeDescription
metadatamappingThe metadata of a submission in the file.

Yields

tuple
Where the value is (such as metadata.sample.by_alias.s1.r__date), the slug of its field, and the value without its empty parts. An empty value is left out: apply writes nothing for it.

object_partsfunction#

def object_parts(schema: Mapping) -> list[dict]

List the parts of an object a metadata field holds, to write it with its keys.

A field of several forms, all objects (such as an instrument of one form per platform), gives every key of its forms; a part that differs from a form to another says what each form expects.

Parameters

NameTypeDescription
schemamappingThe JSON Schema of the field.

Returns

list of dict
Each part with its key, whether every form required it, and what it expected, in words. Empty when the field is not an object, or may be something else than an object (such as a date).

parametersfunction#

def parameters(schemas: Schemas, urls: Iterable[str]) -> dict[str, dict]

Read the schemas of the parameters of a plugin, by key.

madbot checks {key: value} against the schema of each key. A schema holding several keys is split, one object schema per key.

Parameters

NameTypeDescription
schemasSchemasThe schemas of the instance.
urlsiterable of strThe addresses of the schemas, as the plugin gives them.

Returns

dict
The schema of each parameter by its key: an object holding that key, required when its schema requires it.

plugin_hintfunction#

def plugin_hint(plugin: Mapping) -> str

Name the discovery command that describes a plugin.

Parameters

NameTypeDescription
pluginmappingThe plugin, as the API returns it.

Returns

str
Such as “see `madbot-cli plugins ena```.

requirefunction#

def require(client: Client, state: State, manifest: Manifest, environ: Mapping[str, str] | None = None) -> None

Stop when the file gives values madbot would refuse.

Parameters

NameTypeDefaultDescription
clientClientrequiredThe client.
stateStaterequiredWhat madbot holds.
manifestManifestrequiredThe deposit file.
environmappingNoneThe environment holding the credentials.

Raises

CheckError
With every value madbot would refuse.

unnamed_formfunction#

def unnamed_form(error: jsonschema.ValidationError, *, secret: bool = False) -> str | None

Say which part of an object names its form, when the value names none.

The forms of a field are told apart by a fixed part, such as library_layout set to single or paired. A value naming no form fails every form; the error of the first one alone, 'single' was expected, would hide the others.

Parameters

NameTypeDefaultDescription
errorValidationErrorrequiredAn error, maybe of oneOf or anyOf.
secretboolFalseTrue for credentials: the message never shows the value.

Returns

str or None
Such as library_layout: 'PAIRED' names no form; one of 'single' or 'paired'; None when the error is of another kind.

unquoted_datefunction#

def unquoted_date(value: Any) -> datetime.date | None

Find a date YAML read from an unquoted value, such as 2026-11-02.

Parameters

NameTypeDescription
valueAnyA metadata value of the file.

Returns

datetime.date or None
The first date or date and time found in the value, or None.

variant_offunction#

def variant_of(schema: Mapping, value: Any) -> Mapping

Choose the form of a schema a value names by its fixed parts.

An instrument {platform: X, model: …} is checked against the form of platform X, so that the message is about its model, not about every form.

Parameters

NameTypeDescription
schemamappingA JSON Schema, with oneOf or anyOf forms or without.
valueAnyThe value.

Returns

mapping
The form named, merged with the rest of the schema; the schema itself when the value names no single form.