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: object

One option of a step type.

Variables:
  • name (str) – Key under params in the job file.

  • kind (str) – A PARAM_KINDS key.

  • doc (str) – One or two sentences for the reference documentation.

  • default (Any) – Value used when the key is omitted; REQUIRED when 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) – null is 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

coerce

Check a value from a job file and return it in its Python form.

options

Return the allowed values, or None when any value is allowed.

property required: bool#

Whether the parameter must be given.

options() → tuple[Any, ...] | None[source]#

Return the allowed values, or None when 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 as 19.0 become 19, numbers become float and a number pair becomes a tuple.

Raises:

ValueError – If the type, the range or the choice is wrong.