|
| 1 | +# Using Createstub |
| 2 | + |
| 3 | +## Use MIP to install createstubs on a MCU board |
| 4 | + |
| 5 | +It is possible to install the firmware stubber ( createsubs.py or one of its variants) on a MicroPython board. |
| 6 | +This allows you to create the firmware stubs on the board itself, and then copy them to your PC. |
| 7 | + |
| 8 | +mip is a package manager for MicroPython. It is a command line tool that allows you to install packages on a MicroPython board. |
| 9 | +In this case it is best to use `mpremote` that has a built-in `mip` command. |
| 10 | + |
| 11 | +Make sure you have the latest version of `mpremote` installed. |
| 12 | +```bash |
| 13 | +pip install mpremote |
| 14 | +``` |
| 15 | + |
| 16 | +## Install createstubs |
| 17 | + |
| 18 | +Connect your board to your PC and run the following command: |
| 19 | + |
| 20 | +`mpremote mip install github:josverl/micropython-stubber` |
| 21 | +```log |
| 22 | +Install github:josverl/micropython-stubber |
| 23 | +Installing github:josverl/micropython-stubber/package.json to /lib |
| 24 | +Installing: /lib/createstubs.py |
| 25 | +Installing: /lib/createstubs_db.py |
| 26 | +Installing: /lib/createstubs_mem.py |
| 27 | +Installing: /lib/modules.txt |
| 28 | +Done |
| 29 | +``` |
| 30 | + |
| 31 | +## run createstubs |
| 32 | +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. |
| 33 | +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. |
| 34 | + |
| 35 | +Navigate to the folder where you want to create the stubs and run the following command: |
| 36 | +`mpremote mount . exec "import createstubs"` or |
| 37 | +`mpremote mount . exec "import createstubs_mem"` or |
| 38 | + |
| 39 | + |
| 40 | +## low memory devices |
| 41 | + |
| 42 | +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: |
| 43 | + |
| 44 | +| MicroPython release | .mpy version | command | |
| 45 | +|---------------------|--------------|---------| |
| 46 | +| v1.19 and up | 6 | `mpremote mip install github:josverl/micropython-stubber/mpy_v6.json` | |
| 47 | +| v1.12 - v1.18 | 5 | `mpremote mip install github:josverl/micropython-stubber/mpy_v5.json` | |
| 48 | + |
| 49 | +```log |
| 50 | +Install github:josverl/micropython-stubber/mpy_v6.json |
| 51 | +Installing github:josverl/micropython-stubber/mpy_v6.json to /lib |
| 52 | +Installing: /lib/createstubs_mpy.mpy |
| 53 | +Installing: /lib/createstubs_db_mpy.mpy |
| 54 | +Installing: /lib/createstubs_mem_mpy.mpy |
| 55 | +Installing: /lib/modulelist.txt |
| 56 | +``` |
| 57 | +**Note:** The names of the scripts have changed to createstubs_mpy.py, createstubs_db_mpy.py and createstubs_mem_mpy.py |
| 58 | + |
| 59 | +Navigate to the folder where you want to create the stubs and run the following command: |
| 60 | +`mpremote mount . exec "import createstubs_db_mpy"` or |
| 61 | +`mpremote mount . exec "import createstubs_mem_mpy"` |
| 62 | + |
| 63 | +## format the stubs and generate the .pyi files |
| 64 | + |
| 65 | +The stubs are generated in a folder called `stubs` in the current folder. |
| 66 | +You can use stubber to run the `stubgen` tool to format the stubs and generate the .pyi files. |
| 67 | + |
| 68 | +For example: |
| 69 | +```bash |
| 70 | +stubber stub -s ./stubs/micropython-v1_19_1-rp2 |
| 71 | +``` |
| 72 | + |
| 73 | +see [MicroPython Package management](https://docs.micropython.org/en/latest/reference/packages.html?highlight=mip#package-management) |
0 commit comments