view env/lib/python3.9/site-packages/planemo/templates.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
line wrap: on
line source

"""Templating abstraction around jinja2 for Planemo."""
try:
    from jinja2 import Template
except ImportError:
    Template = None  # type: ignore

NO_JINJA2_MESSAGE = ("This functionality requires Jinja2 but this library is "
                     "unavailable. Install with `pip install jinja2`.")


def render(template_str: str, **kwds):
    """Use jinja2 to render specified template."""
    if Template is None:
        raise Exception(NO_JINJA2_MESSAGE)
    template = Template(template_str)
    contents = template.render(**kwds)
    return contents