Recipe#

Work with recipes.

Validation#

Recipes are checked against a JSON Schema that describes their structure and the arguments of all preprocessor functions. The same schema can be used by editors to check recipes while writing them, refer to Recipe validation for details.

For example, to find the problems in a recipe, with their line numbers:

>>> from esmvalcore.recipe import validate_recipe
>>> text = '''
... documentation:
...   title: Example
...   description: Example recipe.
...   authors: [andela_bouwe]
... diagnostics:
...   example:
...     scripts: null
... preprocessors:
...   pp:
...     regird: {}
... '''
>>> for issue in validate_recipe(text):
...     print(issue)
line 11: preprocessors > pp > regird: unknown preprocessor function. Did you mean 'regrid'?

Classes:

RecipeIssue(path, message[, line, column, ...])

A problem found in a recipe.

Functions:

generate_recipe_schema([session])

Generate a JSON Schema for recipes.

validate_recipe(text[, session])

Validate a recipe against the JSON Schema.

class esmvalcore.recipe.RecipeIssue(path: tuple[str | int, ...], message: str, line: int | None = None, column: int | None = None, severity: Literal['error', 'warning'] = 'error')[source]#

A problem found in a recipe.

Parameters:
  • path (tuple[str | int, ...]) – Keys and list indices that lead to the problem in the recipe.

  • message (str) – Description of the problem.

  • line (int | None) – Line number in the recipe file, starting at 1, if known.

  • column (int | None) – Column number in the recipe file, starting at 1, if known.

  • severity (Literal['error', 'warning']) – Errors prevent the recipe from running, warnings do not.

Attributes:

column: int | None = None#
line: int | None = None#
message: str#
path: tuple[str | int, ...]#
severity: Literal['error', 'warning'] = 'error'#
esmvalcore.recipe.generate_recipe_schema(session: Session | None = None) → JSONSchema[source]#

Generate a JSON Schema for recipes.

The schema only allows the projects in the configuration. If ESMValTool is installed, it also lists the provenance tags and references that it defines, refer to References configuration file.

Parameters:

session (Session | None) – The session that defines the projects. If not given, the configuration in esmvalcore.config.CFG is used.

Returns:

A JSON Schema (draft-07) that describes a recipe.

Return type:

JSONSchema

esmvalcore.recipe.validate_recipe(text: str, session: Session | None = None) → list[RecipeIssue][source]#

Validate a recipe against the JSON Schema.

Also runs checks that the schema cannot express. Some combine several parts of the recipe, for example to check that the preprocessor of each variable group is defined in the preprocessors section. Others run code, for example to check that each variable is in the CMOR tables of its project. Keys that are defined more than once, merge keys (<<) that are used more than once or merge the mapping that contains them, and values that parsers of YAML 1.2 read differently are reported as warnings.

Parameters:
  • text (str) – The YAML text of the recipe.

  • session (Session | None) – The session that the recipe will be run with. Its configuration defines which projects, CMOR tables, required facets, and extra facets can be used. If not given, the configuration in esmvalcore.config.CFG is used.

Returns:

The problems found, sorted by their position in the text. The list is empty if the recipe is valid.

Return type:

list[RecipeIssue]