Package: micropython-stubber
Boost MicroPython productivity in VSCodeThe intellisense and code linting that is so prevalent in modern editors, does not work out-of-the-gate for MicroPython projects.
While the language is Python, the modules used are different from CPython , and also different ports have different modules and classes , or the same class with different parameters.Writing MicroPython code in a modern editor should not need to involve keeping a browser open to check for the exact parameters to read a sensor, light-up a led or send a network request.Fortunately with some additional configuration and data, it is possible to make the editors understand your flavor of MicroPython, wether you use one of the pre-compiled firmwares, but also if you run a one-off custom firmware version.]In order to achieve this a few things are needed:Stub files for the native / enabled modules in the firmware using PEP 484 Type HintsSpecific configuration of the VSCode Python extensionsSpecific configuration of Pylint [ Optional ]Suppression of warnings that collide with the MicroPython principals or code optimization.Please review the documentation on [https://micropython-stubber.readthedocs.io]With that in place, VSCode will understand MicroPython for the most part, and help you to write code, and catch more errors before deploying it to your board.Note that the above is not limited to VSCode and pylint, but it happens to be the combination that I use.A lot of subs have already been generated and are shared on PyPi, github or pre-installed by a tool, so it is quite likely that you can just grab a copy be be productive in a few minutes.To install the stubs from PyPIThis section describes how to install the stubs from PyPI, and how to use them in your project.
If you want to create or maintain stub - please see the next section.Install in a typings folder (recommended)pip install -U micropython-<port>[-<board>]stubs --no-user --target ./typingsInstall in a venv (after activating)pip install -U micropython-<port>[-<board>]stubs --no-userExamples:pipinstall-Umicropython-stm32-stubs# Install stubs for a specific version.pipinstall-Umicropython-esp32-stubs==1.20.0.*# Install stubs for a specific board.pipinstall-Umicropython-rp2-pico_w-stubsFor more details how to use the stubs please refer tothe documentation on RTDThe sister-repoMicroPython-stubscontainsall stubsI have collected with the help of others, and which can be used directly.
That repo also contains examples configuration files that can be easily adopted to your setup.A second repomicropy-stubs repomaintained by BradenM, also contains stubs, but in a structure only used and distributed by themicropy-clitool.
You should use micropy-cli to consume stubs from that repo.The (stretch) goal is to create a VSCode add-in to simplify the configuration, and allow easy switching between different firmwares and versions.Install and basic usage of the stubber toolpipinstallmicropython-stubber# go to your working foldercdmy_stub_folder
mkdirall-stubs# clone the micropython repo's and switch to a specific versionstubberclone
stubberswitch--versionv1.18# get the document stubs for the current version ( v1.18 )stubberget-docstubs# get the frozen stubs for the current version ( v1.18 )stubberget-frozen# get the core CPython compatibility stubs from PyPistubberget-core# Update the fallback stubsstubberupdate-fallback#lsall-stubs
dirall-stubsDeveloping & testingThis is described in more detail in thedevelopingandtestingdocuments in the docs folder.Branch MainThe name of the default branch has been changed tomain.
If you have cloned this repo before you main need to adjust the local repro to be aware of this, or create a fresh clone.To update run the below command:gitbranch-mmastermaingitfetchorigin
gitbranch-uorigin/mainmaingitremoteset-headorigin-afor more info seeRenaming a branchLicensingMicroPython-Stubber is licensed under the MIT license, and all contributions should follow thisLICENSE.ContributionsJos Verlinde💻🔬🤔🖋📚✔Thonny, Python IDE for beginners🤔🔬MicroPython🔣📚pyright🔧Boris Lovosevic🔣📚Paul Sokolovsky🔣📚pycopy🔣📚Pycom🚇Braden Mars🐛💻📚📦James Manners💻🐛Patrick🐛💻📚Paul m. p. P.🤔🔬Edward K. Ream🔌Daryl Stultz📚Keeping things together🐛vbolshakov🐛📚Mauro Riva📝🐛MathijsNL🐛Callum Jacob Hays🐛✔Zoltán Vörös🔣vincent-l-j📖Egor Litvinov🐛Sam Duke💻This project follows theall-contributorsspecification. Contributions of any kind welcome!