def interpolate_value(value: str, context: dict):
"""Expand Jinja templating in the definitions."""
if type(value) == str and "{{" in value:
t = jinja2.Template(value, undefined=jinja2.StrictUndefined)
try:
v = t.render(**context)
except jinja2.exceptions.TemplateError as e:
raise RuntimeError("Could not expand template value: {}".format(value)) from e
# Jinja template rendering does not have explicit int support,
# so we have this hack in place
try:
v = int(v)
except ValueError:
pass
return v
else:
return value
评论列表
文章目录