Add a loader to enable jinja imports#88624
Conversation
|
Duplicate of #85665 |
|
@balloob Thanks for the pointers. Quick question: if the issue is primarily I/O in the event loop, would it be ok to preload these files (in the given directory) into memory at startup or when a service is called to reload (like with automations) so that import never does I/O? Then we would use DictLoader in the template environment so that imports never go to disk. |
|
Yeah, I think that could work. Let me give it some thoughts on how we would want this to be exposed to users. |
|
Awesome. I have some prototype code (just wanted to see what it would take to load everything into memory -- very straightforward) updated in my branch that does this, though I haven't hooked it into any lifecycle yet (just happens once at startup at the moment). Happy to hack on it if you have suggestions for the shape it should take. |
Breaking change
Proposed change
Breaking out part of #88575
Enables importing/including shared jinja code/macros from a
custom_jinjafolder in your config folder.All of this enables the following code:
In config/custom_jinja/shared.jinja:
Elsewhere:
With the following output:
I'm happy to update the documentation as well but wanted to first clear that this would be a welcome change.
Type of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: