qgis_deployment_toolbelt.jobs.options module¶
Base model of the QDT jobs options, built on pydantic.
The options of a job are declared as a JobOptions subclass, one annotated
field per option, and validated with JobOptions.from_dict():
an option with a default value is optional, an option without one is required;
unknown options are rejected;
values are checked strictly: no conversion (
"5"is not accepted for an int);validated options are read-only.
Validation errors are raised as the QDT job options exceptions, to keep the same
messages and except clauses as the legacy OPTIONS_SCHEMA validation.
Example
class ExampleOptions(JobOptions):
mode: Literal["fast", "safe"] = "safe"
threads: int = 5
source: str # no default: required
options = ExampleOptions.from_dict({"source": "here"}, job_id="example-job")
options.mode # "safe"
Author: Julien Moura (https://github.com/guts)
- class qgis_deployment_toolbelt.jobs.options.JobOptions¶
Bases:
BaseModelBase of the options of a job.
- _abc_impl = <_abc._abc_data object>¶
- classmethod _to_qdt_error(error: ErrorDetails, job_id: str) Exception¶
Translate a pydantic validation error into a QDT job option exception.
- Parameters:
error – first error of the pydantic ValidationError
job_id – job identifier, used in error messages
- Returns:
exception to raise
- classmethod from_dict(options: Mapping[str, Any] | None, job_id: str) Self¶
Validate the options set in the
withkey of a scenario step and complete them with the default values.- Parameters:
options – options to validate. None (step without
withkey) means that the default values apply and the required options are reported missing.job_id – job identifier, used in error messages
- Raises:
TypeError – if options is neither a mapping nor None
JobOptionBadNameError – if an option is not declared
JobOptionMissingError – if a required option is not set
JobOptionBadValueTypeError – if an option value has the wrong type
JobOptionBadValueError – if an option value is not accepted
- Returns:
validated options
- model_config = {'extra': 'forbid', 'frozen': True, 'strict': True, 'validate_default': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].