Jinja templating can be optimised
Creating a new jinja Loader and Environment for each template file is a little waste of resources.
We could create a single Environment for the whole script and generate overlays for extras like addons
and admin-tools
with specific loader, environments are passed down to genTemplate
:
def cli():
default_loader = FileSystemLoader('templates')
default_env = Environment(loader=default_loader)
# […]
# gen_socle() use defaults
def gen_addon(ctx, name=None, addon_config=None):
addon_path = join('addons', name)
# Addons load templates from its directory first then fallback to top level `templates/`
addon_loader = FileSystemLoader([
join(addon_path, 'templates'),
join(root_dir, 'templates')
])
addon_env = default_env.overlay(loader=addon_loader)
# […]
def gen_admin_tool(ctx, name=None, admin_tool_config=None):
admin_tool_path = join('admin-tools', name)
# Admin_Tools load templates from its directory first then fallback to top level `templates/`
admin_tool_loader = FileSystemLoader([
join(admin_tool_path, 'templates'),
join(root_dir, 'templates')
])
admin_tool_env = default_env.overlay(loader=admin_tool_loader)
# […]