-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3724: Add custom jinja2 test. Rename site recipes file. Revise docs
- Loading branch information
1 parent
dcf65b1
commit 193c5a0
Showing
3 changed files
with
48 additions
and
22 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
esmvaltool/utils/recipe_test_workflow/Jinja2Tests/file_exists.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,37 @@ | ||
""" | ||
Module for custom Jinja2 Tests. | ||
In Jinja2 "tests" are used to test a variable against an expression. | ||
Refer to Jinja2 tests: | ||
https://jinja.palletsprojects.com/en/stable/templates/#tests | ||
Jinja2 has a number of Builtin tests: | ||
https://jinja.palletsprojects.com/en/stable/templates/#list-of-builtin-tests | ||
Jinja2 also allows for writing custom tests in Python: | ||
https://jinja.palletsprojects.com/en/stable/api/#custom-tests | ||
Cylc supports custom filters, tests and globals as described here: | ||
https://cylc.github.io/cylc-doc/stable/html/user-guide/writing-workflows/jinja2.html#custom-jinja2-filters-tests-and-globals | ||
""" | ||
from pathlib import Path | ||
|
||
|
||
def file_exists(file_path): | ||
""" | ||
Test if a file exists. | ||
Parameters | ||
---------- | ||
file_path : str | ||
A file path. | ||
Returns | ||
------- | ||
bool | ||
Returns True if the file exists. | ||
""" | ||
run_directory = Path.cwd() | ||
site_recipes_file_path = run_directory / file_path | ||
return site_recipes_file_path.is_file() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 15 additions & 10 deletions
25
...test_workflow/site/metoffice-recipes.cylc → ...est_workflow/site/metoffice-recipes.jinja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters