It is possible to install the firmware stubber ( createstubs.py or one of its variants) on a MicroPython board. This allows you to create the firmware stubs on the board itself, and then copy them to your PC.
mip is a package manager for MicroPython. It is a command line tool that allows you to install packages on a MicroPython board.
In this case it is simplest to use mpremote as that has a built-in mip command.
Make sure you have the latest version of mpremote installed.
pip install mpremoteConnect your board to your PC and run the following command:
mpremote mip install github:josverl/micropython-stubber
Install github:josverl/micropython-stubber
Installing github:josverl/micropython-stubber/package.json to /lib
Installing: /lib/createstubs.py
Installing: /lib/createstubs_db.py
Installing: /lib/createstubs_mem.py
Installing: /lib/modules.txt
Done
| Other packages | command |
|---|---|
| full/debug | mpremote mip install github:josverl/micropython-stubber/mip/full.json |
| minified (default) | mpremote mip install github:josverl/micropython-stubber/mip/minified.json |
Note : If you need to install from a specific branch or tag, then append
@branchnameor@tagnameto the URL.
A simple way to run createstubs is to use the mpremote mount command to allow the MCU board to directly access the PC's file system.
Then you can run the createstubs.py script directly from the MCU board with outh the need to copy the created files back to the PC.
Navigate to the folder where you want to create the stubs and run the following command:
mpremote mount . exec "import createstubs" or
mpremote mount . exec "import createstubs_mem" or
If you have a low memory board, then you can install the cross-compiled variants to reduce the memory footprint durign compilation on the board:
| MicroPython release | .mpy version | command |
|---|---|---|
| v1.19 and up | 6 | mpremote mip install github:josverl/micropython-stubber/mip/mpy_v6.json |
| v1.12 - v1.18 | 5 | mpremote mip install github:josverl/micropython-stubber/mip/mpy_v5.json |
Install github:josverl/micropython-stubber/mpy_v6.json
Installing github:josverl/micropython-stubber/mpy_v6.json to /lib
Installing: /lib/createstubs_mpy.mpy
Installing: /lib/createstubs_db_mpy.mpy
Installing: /lib/createstubs_mem_mpy.mpy
Installing: /lib/modulelist.txt
Note: The names of the scripts have changed to createstubs_mpy.py, createstubs_db_mpy.py and createstubs_mem_mpy.py
Navigate to the folder where you want to create the stubs and run the following command:
mpremote mount . exec "import createstubs_db_mpy" or
mpremote mount . exec "import createstubs_mem_mpy"
The stubs are generated in a folder called stubs in the current folder.
you can use stubber to run the stubgen tool to format the stubs and generate the .pyi files.
stubber stub -s .\stubs\micropython-v1_19_1-rp2\