Page MenuHomeVyOS Platform

Rework vyos.template Python module to make future extension easier
Open, LowPublic

Description

Hi,

I reworked the vyos.template module to make it cleaner and allow for jinja2 template filters to be added more easily in the future.

Notable things I changed:

  • Removed the custom caching of compiled templates. Jinja2 does this itself by default and allows to specify the max number of templates to cache. I set it to 100 for now.
  • Pass auto_reload=False to jinja2 environment creation. Without this, jinja2 will check if a once loaded template file has changed upon re-rendering, which I'm pretty sure we don't need because template files never change during the run of a Python process, right?
  • Added a register_filter() function which allows registering additional template filters. This is more flexible than hardcoding the filters at environment creation and also allows other modules to register their own specific filters outside of vyos.template.

What do you think of these changes?

PR will follow once this has a task number.

Best regards
Robert

Details

Difficulty level
Unknown (require assessment)
Version
-
Why the issue appeared?
Will be filled on close
Is it a breaking change?
Perfectly compatible
Issue type
Internal change (not visible to end users)

Event Timeline

efficiosoft created this task.
efficiosoft created this object in space S1 VyOS Public.

While you are working on this, there is a need for a render function that does return the template as an variable instead of saving it to a file.
could you extend your patch to also include such a function? if written correctly it could be used by the render() function to not duplicate code.

erkin set Issue type to Internal change (not visible to end users).Aug 29 2021, 1:46 PM
erkin removed a subscriber: Active contributors.