Add module pre-compile to fix some import errors #19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Due to the lack of memory, some boards are not able to properly load this module.
As explained in the official MicroPython docs, when a module is imported, MicroPython compiles the code to bytecode which is then executed by the MicroPython virtual machine. The bytecode is stored in RAM and the compiler itself temporarily requires RAM! Thus, the situation can arise where there is insufficient RAM to run the compiler. In this case the import statement will produce a memory exception.
A viable solution is to precompile modules, such that the compiler will not need RAM space. MicroPython has a cross compiler capable of compiling Python modules to bytecode (
mpy-cross
). The resulting bytecode file has a.mpy
extension and it may be copied to the filesystem and imported in the usual way.A better option is to make your own firmware and implement the module as frozen bytecode, because on most platforms this saves even more RAM as the bytecode is run directly from flash rather than being stored in RAM.
This PR introduces a GitHub Workflow that pre-compiles the module and uploads the
.mpy
files as artifacts.