Coverage for src/CSET/cset_workflow/app/parbake_recipes/bin/parbake.py: 100%
18 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 21:08 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-05 21:08 +0000
1#!/usr/bin/env python3
2# © Crown copyright, Met Office (2022-2025) and CSET contributors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
16"""Run a recipe with the CSET CLI."""
18import json
19import os
20from base64 import b64decode
21from pathlib import Path
23from CSET.recipes import load_recipes
26def parbake_all(variables: dict, rose_datac: Path, share_dir: Path, aggregation: bool):
27 """Generate and parbake recipes from configuration."""
28 # Gather all recipes into a big list.
29 recipes = list(load_recipes(variables))
30 # Check we have some recipes enabled.
31 if not recipes:
32 raise ValueError("At least one recipe should be enabled.")
33 # Parbake all recipes remaining after filtering aggregation recipes.
34 for recipe in filter(lambda r: r.aggregation == aggregation, recipes):
35 print(f"Parbaking {recipe}", flush=True)
36 recipe.parbake(rose_datac, share_dir)
39def main():
40 """Program entry point."""
41 # Gather configuration from environment.
42 variables = json.loads(b64decode(os.environ["ENCODED_ROSE_SUITE_VARIABLES"]))
43 rose_datac = Path(os.environ["ROSE_DATAC"])
44 share_dir = Path(os.environ["CYLC_WORKFLOW_SHARE_DIR"])
45 aggregation = bool(os.getenv("DO_CASE_AGGREGATION"))
46 # Parbake recipes for cycle.
47 parbake_all(variables, rose_datac, share_dir, aggregation)
50if __name__ == "__main__": # pragma: no cover
51 main()