Skip to content

Commit

Permalink
Remove Template references for now
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidHuber-NOAA committed May 3, 2024
1 parent 86fee43 commit 1873fee
Showing 1 changed file with 0 additions and 28 deletions.
28 changes: 0 additions & 28 deletions src/wxflow/jinja.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import jinja2
from markupsafe import Markup

from .template import TemplateConstants, Template
from .timetools import (add_to_datetime, strftime, to_fv3time, to_isotime,
to_julian, to_timedelta, to_YMD, to_YMDH)

Expand Down Expand Up @@ -111,22 +110,12 @@ def get_set_env(self, loader: jinja2.BaseLoader, filters: Dict[str, callable] =
getenv: read variable from environment if defined, else UNDEFINED
to_timedelta: convert a string to a timedelta object
add_to_datetime: add time to a datetime, return new datetime object
template_substitute_structure: traverses a dictionary and substitutes
variables in fields, lists, and nested dictionaries
The Expression Statement extension "jinja2.ext.do", which enables
{% do ... %} statements. These are useful for appending to lists.
e.g. {{ bar.append(foo) }} would print "None" to the parsed jinja
template, but {% do bar.append(foo) %} would not.
Additionally, the following TemplateConstants are passed into the
environment:
DOLLAR_CURLY_BRACE
DOLLAR_PARENTHESES
DOUBLE_CURLY_BRACES
AT_SQUARE_BRACES
AT_ANGLE_BRACKETS
Parameters
----------
loader: jinja2.BaseLoader
Expand All @@ -141,12 +130,6 @@ def get_set_env(self, loader: jinja2.BaseLoader, filters: Dict[str, callable] =

env = jinja2.Environment(loader=loader, undefined=self.undefined)

env.globals["DOLLAR_CURLY_BRACE"] = TemplateConstants.DOLLAR_CURLY_BRACE
env.globals["DOLLAR_PARENTHESES"] = TemplateConstants.DOLLAR_PARENTHESES
env.globals["DOUBLE_CURLY_BRACES"] = TemplateConstants.DOUBLE_CURLY_BRACES
env.globals["AT_SQUARE_BRACES"] = TemplateConstants.AT_SQUARE_BRACES
env.globals["AT_ANGLE_BRACKETS"] = TemplateConstants.AT_ANGLE_BRACKETS

env.add_extension("jinja2.ext.do")

env.filters["strftime"] = lambda dt, fmt: strftime(dt, fmt)
Expand All @@ -163,17 +146,6 @@ def get_set_env(self, loader: jinja2.BaseLoader, filters: Dict[str, callable] =
if not (isinstance(dt, SilentUndefined) or isinstance(delta, SilentUndefined))
else dt if isinstance(dt, SilentUndefined) else delta)
env.filters["to_timedelta"] = lambda delta_str: to_timedelta(delta_str) if not isinstance(delta_str, SilentUndefined) else delta_str
env.filters["template_substitute_structure"] = (
lambda structure_to_substitute, var_type, get_value:
Template.substitute_structure(structure_to_substitute,
var_type,
get_value)
if not (isinstance(structure_to_substitute, SilentUndefined) or
isinstance(var_type, SilentUndefined) or
isinstance(get_value, SilentUndefined))
else structure_to_substitute if isinstance(structure_to_substitute, SilentUndefined)
else var_type if isinstance(var_type, SilentUndefined)
else get_value)

# Add any additional filters
if filters is not None:
Expand Down

0 comments on commit 1873fee

Please sign in to comment.