Freezing the templates folder into the binary #227
Replies: 5 comments 4 replies
-
I have good news for you. Templates need to be compiled before they are used. The compiled code is actually Python. You can compile your templates on your desktop/laptop if you want, then configure the uTemplate integration in Microdot to not attempt to compile, just load the pre-compiled versions that are Python code. I explained how to do this in this comment. Since this all ends up being Python code, it's absolutely no issue to freeze your templates. |
Beta Was this translation helpful? Give feedback.
-
Use
In boot.py you can then do uncompress, which will automatically create the directory templates.
I disagree with your solution because I believe that the resulting python compile result depends on the variables you pass. |
Beta Was this translation helpful? Give feedback.
-
I don't know what freezefs is, I have never used it. By "freezing" I meant compiling a custom firmware as explained here: https://docs.micropython.org/en/latest/reference/manifest.html. |
Beta Was this translation helpful? Give feedback.
-
It's called freezefs, because it allows you to freeze a non-python file or directory into your micropython image. My current procedure is. I call manifest.py, this freezes the required folders and pushes these into my package. |
Beta Was this translation helpful? Give feedback.
-
uTemplate compiles templates to standard Python files, as I said above. No need to freeze the actual template files, you can pre-compile and then freeze the compiled Python files. That also eliminates the need for uTemplate to compile the templates in your device. |
Beta Was this translation helpful? Give feedback.
-
I am thinking of freezing the templates directory used by utemplate into the micropython binary, so I can roll updates via
github:glenn20/micropython-esp32-ota/mip/ota/mpy
. Do you think this is a good idea? Typically, all my static resources are small. There are ways of freezing non python code into the binary, see https://github.com/orgs/micropython/discussions/10707 . Especially, https://github.com/bixb922/freezefs seems interesting as it also calculates ram usage. I think it requires small changes to microdot/utemplate.py, as I need to pick up the template from the memory and compile to the flash memory.Another option I see is to roll the OTA update and then install the non-python assets via a mip install and package.json https://docs.micropython.org/en/latest/reference/packages.html
Beta Was this translation helpful? Give feedback.
All reactions