Skip to content

trestle.core.jinja.ext

trestle.core.jinja.ext ¤

Trestle core.jinja extension loading functionality.

Attributes¤

logger = logging.getLogger(__name__) module-attribute ¤

Classes¤

Functions¤

extensions() cached ¤

Return list of Jinja extensions packaged with compliance-trestle and included from plugins.

Source code in trestle/core/jinja/ext.py
28
29
30
31
32
33
34
35
36
37
38
39
40
@functools.cache
def extensions() -> List[Extension]:
    """Return list of Jinja extensions packaged with compliance-trestle and included from plugins."""
    extensions = [tags.MDSectionInclude, tags.MDCleanInclude, tags.MDDatestamp, filters.JinjaSSPFilters]
    # This block is uncovered as trestle cannot find plugins in it's unit tests - it is the base module.
    for plugin, ext_cls in discovered_plugins('jinja_ext'):  # pragma: nocover
        # add extensions (derived from TrestleJinjaExtension) to extensions list
        if issubclass(ext_cls, Extension):
            # don't add Extension or TrestleJinjaExtension
            if ext_cls is not TrestleJinjaExtension and ext_cls is not Extension:
                extensions.append(ext_cls)
                logger.info(f'{ext_cls} added to jinja extensions from plugin {plugin}')
    return extensions

handler: python