Param#
- class rapidtools.jobs.Param(name: str, kind: str, doc: str, default: Any = REQUIRED, choices: tuple[Any, ...] | Callable[[], tuple[Any, ...]] | None = None, secret: bool = False, nullable: bool = False, minimum: float | None = None, maximum: float | None = None, exclusive_minimum: float | None = None, field: str | None = None)[source]#
Bases:
objectOne option of a step type.
- Variables:
name (str) – Key under
paramsin the job file.kind (str) – A
PARAM_KINDSkey.doc (str) – One or two sentences for the reference documentation.
default (Any) – Value used when the key is omitted;
REQUIREDwhen it must be given.choices (tuple | Callable[[], tuple] | None) – Allowed values. A callable is evaluated on first use so that listing them does not import heavy modules.
secret (bool) – The value is a credential: it may be written as a secret reference and never appears in logs or result files.
nullable (bool) –
nullis accepted.minimum (float | None) – Smallest allowed value.
maximum (float | None) – Largest allowed value.
exclusive_minimum (float | None) – The value must be greater than this.
field (str | None) – Name of the matching settings field when it differs from
name.
Example
>>> zoom = Param('zoom', 'integer', 'Tile zoom level.', default=19, ... minimum=10, maximum=21) >>> zoom.coerce(18.0), zoom.required (18, False)
Methods
Check a value from a job file and return it in its Python form.
Return the allowed values, or
Nonewhen any value is allowed.- options() tuple[Any, ...] | None[source]#
Return the allowed values, or
Nonewhen any value is allowed.
- coerce(value: Any) Any[source]#
Check a value from a job file and return it in its Python form.
JSON types are enforced strictly (
"19"is not an integer), so a mistake is reported instead of being guessed at.- Parameters:
value (Any) – The decoded JSON value.
- Returns:
Any –
value; integers written as19.0become19, numbers becomefloatand a number pair becomes a tuple.- Raises:
ValueError – If the type, the range or the choice is wrong.