Add a FileSystemLoader to load external Jinja templates#85665
Add a FileSystemLoader to load external Jinja templates#85665DanielBaulig wants to merge 2 commits into
Conversation
|
This would be one of the best additions to Home Assistant ever. Please don't let this go idle. |
|
@balloob Thanks Paulus for pointing me to the previous discussion of equivalent changes. If I would like to make the case in favor of the change and provide arguments for why I think this is something that should be considered to be merged into HA core, where would the right place be? It seems the two other mentioned pull requests have been locked. In case here is the right place I would like to make an attempt at summarizing the main objections / open questions to these pull requests, just to make sure we're on the same page on what the perceived issue with this approach is. Please let me know if I am missing any major concerns / problems. I've gathered all these points/questions from the two pull requests linked above.
I also see some alternatives suggested, in particular:
|
|
The major issue here is I/O in event loop. It halts the whole system so is not allowed. Needs to be done in executor. That means you need |
Proposed change
Adds a Jinja2 FileSystemLoader to enable loading of external templates within Home Assistant Jinja templates. Effectively activates support for
{% include 'template.j2' %}and{% import template.j2 as t %}, which in combination with macros allow for the easy user side definition and reuse of templates and template macros throughout Home Assistant, e.g.config/templates/mymacros.j2
Template Developer Tools
All external template files must be located in the "templates" subdirectory of the Home Assistant config directory.
Type of change
Additional information
Checklist
I have two pre-commit hooks fail that I skipped using --no-verify.
The mypy error I'm not sure I understand or how to address. The other one seems to be an infrastructure and not a my code problem.
I'd love some help understanding and fixing these.
black --fast homeassistant tests)I believe one of the pre-commit hooks ran black
I have not added any tests so far.
If user exposed functionality or configuration variables are added/changed:
I have not added any documentation so far.
To help with the load of incoming pull requests:
I don't have a lot of python experience and am not sure if I'll be of much value here.