Josverl / micropython-stubs

Stubs of most MicroPython ports, boards and versions to make writing code that much simpler.
https://micropython-stubs.readthedocs.io
MIT License
133 stars 21 forks source link

Not clear on how to properly install stubs? #753

Open VirtualWolf opened 2 months ago

VirtualWolf commented 2 months ago

First a disclaimer, forgive me if this seems dense but I'm relatively new to this. 😅

I was looking at the list of firmware, I have an Unexpected Maker FeatherS2 ESP32 board and want to install the "frozen" stub for MicroPython 1.22.2 for that specific board. I see it exists on that page towards the bottom, and in the repository here, but if I search PyPi for just "frozen" there's only a handful of random boards listed, none of them up to date, and no sign of the FeatherS2 at all.

Are the stubs/frozen stubs/etc. in this repository meant to be all published to PyPi automatically? If not, is there some other specific method that's recommended to get them installed?

Thanks!

Josverl commented 2 months ago

I publish a combination of the firmware, do stubs and frozen stubs to Pypi.

As I don't have the firmware stubs for your board specifically, you could install the micropython-esp32-stubs and download and add any extra frozen stubs.

Or you could run the firmware stubber on your board, and generate a complete package yourself. Happy to assist as the docs on that are not yet written...

VirtualWolf commented 2 months ago

Or you could run the firmware stubber on your board, and generate a complete package yourself. Happy to assist as the docs on that are not yet written...

Oh sure, happy to help with running that!

Josverl commented 2 months ago

@VirtualWolf

Not sure what OS you are using; but can you try to follow this 5 step process, and let me know what did / did not work for you , or how to improve ?

https://gist.github.com/Josverl/76e65c96c0c9d43b9c54031fa1e4aa24

VirtualWolf commented 2 months ago

Oops, sorry for the long delay, for some reason GitHub didn't actually send me a notification of your comment!

It was looking good right up until the end when it fell over:

(.venv) [virtualwolf@shade:~/Downloads/stubber]$ stubber get-mcu-stubs
21:59:28 | INFO     | cli                - micropython-stubber 1.20.0
[...]
22:04:08|INFO    |runner               - All modules have been processed, Finalizing report
22:04:08|INFO    |runner               - Path: /remote/stubs/micropython-v1_22_2-esp32-ESP32_GENERIC
22:04:08|INFO    |runner               - Local directory /var/folders/44/4d8w03kx2_73d_ps6vr5smvr000101/T/board_stubber0ycjf9wc is mounted at /remote
22:04:09|INFO    |post                 - Running autoflake on: /var/folders/44/4d8w03kx2_73d_ps6vr5smvr000101/T/board_stubber0ycjf9wc/stubs/micropython-v1_22_2-esp32-ESP32_GENERIC
22:04:10|SUCCESS |mcu_stubber          - Stubs generated for esp32-ESP32_GENERIC
22:04:10|SUCCESS |mcu_stubber          - Stubs copied to repos/micropython-stubs/stubs/micropython-v1_22_2-esp32-ESP32_GENERIC
22:04:10|INFO    |mcu_stubber          - Merging stubs with docstubs : {'version': '1.22.2', 'mpy': 'v6.2', 'port': 'esp32', 'board': 'ESP32_GENERIC', 'family': 'micropython', 'build': '', 'arch': 'xtensawin', 'ver': '1.22.2', 'cpu': 'ESP32'}
22:04:21|INFO    |merge_docstubs       - checking 1 possible board candidates
22:04:21|INFO    |merge_docstubs       - Merge v1.22.2 docstubs with boardstubs to micropython-v1_22_2-esp32-ESP32_GENERIC-merged
22:04:33|INFO    |merge_docstubs       - merged 1 of 1 candidates
22:04:33|INFO    |mcu_stubber          - Building package for {'version': '1.22.2', 'mpy': 'v6.2', 'port': 'esp32', 'board': 'ESP32_GENERIC', 'family': 'micropython', 'build': '', 'arch': 'xtensawin', 'ver': '1.22.2', 'cpu': 'ESP32'}
22:04:34|INFO    |publish              - checking 1 possible board candidates
22:04:34|INFO    |stubpackage          - Build: micropython-v1_22_2-esp32-esp32_generic-stubs
22:04:34|INFO    |stubpackage          - - Update micropython-v1_22_2-esp32-esp32_generic-stubs
22:04:34|ERROR   |stubpackage          - Exception on process, [Errno 2] No such file or directory: 'poetry'
22:04:34|INFO    |stubpackage          - micropython-esp32-esp32_generic-stubs: skip - Could not build/update package

I did a pip install poetry and reran it and it worked! 🎉 I'll see about submitting a PR this weekend with those docs polished a bit. (This was all in a venv with Python 3.12.2 under macOS 14.

In terms of boards where the repository does have the stubs for it, which was more of the impetus for my original question, would the process to get the typings installed for VSCode be something like:

?

My main confusion was that just running pip install mostly appears not to work because PyPi doesn't have the vast majority of the typings...