Skip to content

Commit

Permalink
#3724: Custom Jinja2Test for missing site file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbillowsMO committed Jan 20, 2025
1 parent ae48dfc commit 06e50cd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from pathlib import Path

def file_exists(file_path):
run_directory = Path.cwd()
site_recipes_file_path = run_directory / file_path
return site_recipes_file_path.is_file()
26 changes: 16 additions & 10 deletions esmvaltool/utils/recipe_test_workflow/flow.cylc
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@
{{ assert(SITE != "", "SITE must be set to something other than an empty string") }}

{% set SITE_RECIPES_FILE = "site/" ~ SITE ~ "-recipes.cylc" %}
{% set MISSING_FILE_MSG =
"'" ~ SITE_RECIPES_FILE ~ "' is required for the Recipe Test Workflow and was not "
"found - the 'How to add a recipe to the RTW' documentation provides more "
"information"%}
{% set UNDEFINED_VARIABLE_MSG =
"variable must be set in your '" ~ SITE_RECIPES_FILE ~ "'- the 'How to add a recipe "
"to the RTW' documentation provides more information."%}

# --- Leave a blank line below for a clean error message ---
# Assert 'site/<site>-recipes.cylc' exists and assert FAST_RECIPES and MEDIUM_RECIPES
# are imported from it. Produce readable errors if not.
# --- Text in the three lines above an assert appears in the Jinja2 error ---

# If you see `<-- TemplateNotFound` error below, a `<site>-recipes.cylc` file is missing from the `site` directory.
# Refer to the the 'How to add a recipe to the RTW' documentation for more information.
{% include SITE_RECIPES_FILE %}


{{ assert(SITE_RECIPES_FILE is file_exists, MISSING_FILE_MSG) }}
{% from SITE_RECIPES_FILE import FAST_RECIPES, MEDIUM_RECIPES %}
# --- Text in the three lines above an assert appears in the Jinja2 error ---


{% set ERROR_MSG =
"is undefined and must be set in '" ~ SITE_RECIPES_FILE ~ "' - the 'How to "
"add a recipe to the RTW' documentation provides more information."
%}

{{ assert(FAST_RECIPES is defined, "FAST_RECIPES " ~ ERROR_MSG)}}
{{ assert(MEDIUM_RECIPES is defined, "MEDIUM_RECIPES " ~ ERROR_MSG)}}
{{ assert(FAST_RECIPES is defined, "The FAST_RECIPES " ~ UNDEFINED_VARIABLE_MSG) }}
{{ assert(MEDIUM_RECIPES is defined, "The MEDIUM_RECIPES " ~ UNDEFINED_VARIABLE_MSG) }}

[scheduler]
UTC mode = True
Expand Down

0 comments on commit 06e50cd

Please sign in to comment.