mip: Better support for natmod installations#1140
Conversation
ce8ef66 to
5d4e25d
Compare
Allows to use a single URL to specify a native module package, and mip will then lookup the correct hardware architecture and MicroPython ABI version. Signed-off-by: Jon Nordby <jononor@gmail.com>
5d4e25d to
c3cee68
Compare
|
I see the need for a solution to this problem, and i like the simplicity of the solution. To me the MPY_ARCH and MPY_VERSION placeholders are a bit magical. Apart from some bikeshedding on the prefix , MP / MPY , Possibly that can also be solved by a |
|
Yeah they are somewhat magical - I added a minimum of docs in micropython/micropython#19478 - that can also be expanded. There actually is example code in the docs already for getting this arch/version stuff out - https://docs.micropython.org/en/latest/reference/mpyfiles.html#versioning-and-compatibility-of-mpy-files I have no opinion on the prefix - will adopt whatever the maintainers think appropriate. Currently there is a mix of MP and MPY in codebase - where the MPY is mostly what is used around .mpy files, like in mpy_ld.py etc. Seeing the exact URL would be useful. There is print of "downloading XYZ" from mip.install now - but it actually happens before URL rewriting - so will show the variables. This affects not only the expansion of these variables, but also github: prefix expansion. |
Summary
It is possible to install .mpy files using mip, including those that have native code (native modules). But currently one must specify the exact file URL for such files - which for native modules means knowing the correct ABI version and architecture version - something users rarely know offhand. This makes it difficult to document how to install a natmod, and makes it difficult to have scripts that automatically install the correct version.
This change allows using a single URL to specify a native module package - regardless of the ABI/architecture. mip will then lookup the correct hardware architecture and MicroPython ABI version, and substitute this into the URL before doing the download/install.
The use of variables that are substituted allows some flexibility wrt different locations/layouts for .mpy files. This is useful because there is currently no standard (to my knowledge) for how to lay out. So this should be immediately useful to existing distributions of mpy natmods.
Note: for
import footo work the .mpy file, the file itself must be namedfoo.mpy. Thus the MPY_ARCH and MPY_VERSION markers can only meaningfully be in directory part of a path.Testing
Tested on RP2 port using a Pico W. Example code follows.
Installs from https://github.com/emlearn/emlearn-micropython project - should work on any hardware supported by emlearn-micropython. By removing the network part, should also work on Unix port.
Trade-offs and Alternatives
Small increase in code size of the mip package.
It adds nothing to the core runtime of MicroPython. An alternative implementation that would do versioned/architecture handling at import time would likely increase size of the code.
Generative AI
I did not use generative AI tools when creating this PR.