Closed DavidHuber-NOAA closed 4 months ago
Attention: Patch coverage is 50.00000%
with 1 lines
in your changes are missing coverage. Please review.
Project coverage is 47.87%. Comparing base (
2c48c56
) to head (1873fee
).
Files | Patch % | Lines |
---|---|---|
src/wxflow/jinja.py | 50.00% | 0 Missing and 1 partial :warning: |
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
After a conversation with @aerorahul, I removed the Template
-based filter. I will instead write a method in the Jinja class to handle substitution using regex in a separate PR.
Description This adds ~three~ new features to the
Jinja
class:1.Template.substitute_structure
is now available as a filter. This is useful for parsing jinja templates that reference multiple similar variables (e.g. ensemble member directories). A template for the ensemble members can be passed into the jinja context dictionary and used to construct the final variables based on iterators, cycle date/time, etc.data/YYYYMMDD/HH/analysis/mem###
, one could define'ANALYSIS_tmpl' : "data/${YMD}/{HH}/analysis/mem{MEM}", 'current_cycle': datetime.datetime(year=2024, month=5, day=3, hour=6)
~
{% set cycle_YMD = to_YMD(current_cycle) %}
~ ~{% set cycle_HH = strftime(current_cycle, "%H") %}
~ ~{% for mem in range(1,21) %}
~ ~{% set mem3 = '%03d' % mem %}
~ ~{% set tmpl_dict = {'YMD': cycle_YMD, 'HH': cycle_HH, 'MEM': mem3} %}
~ ~{{ ANALYSIS_tmpl | template_substitute_structure(DOLLAR_CURLY_BRACE, tmpl_dict.get) }}
~ ~{% endfor %}
~Add the
jinja.ext.do
extension to Jinja. This enables{% do ... %}
statements which execute a command for which the output should not be saved. A useful example is appending to a list. Since lists in Python returnNone
, "None" would be written to the parsed jinja template in the following example:{% set a_list = [] %}{{ a_list.append("foo") }}
. Instead, one can now use do:Lastly, this updates the
lambda
function for theadd_to_datetime
filter so anySilentUndefined
input will return aSilentUndefined
, preventing obscure failures.This is needed for noaa-emc/global-workflow#2491 Type of change
How Has This Been Tested?
Checklist