import jinja2


def generate_template(templatename, **kwargs):
    """This renders a JINJA template as a generator.

    The templates exist in our lib/python/treadmill/templates directory.

    :param ``str`` templatename:
        The name of the template file.
    :param ``dict`` kwargs:
        key/value passed into the template.
    """
    jinja_env = jinja2.Environment(loader=jinja2.PackageLoader('treadmill'))
    template = jinja_env.get_template(templatename)
    return template.generate(**kwargs)