Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/josverl/micropython-stubber
Generate and maintain stubs for different MicroPython ports to use with VSCode and Pylance, PyRight, Thonny, PyCharm or MyPy
https://github.com/josverl/micropython-stubber
firmware-stubs micropython micropython-stubber micropython-stubs mypy mypy-stubs pylance pyright python static-typing typed vscode
Last synced: 3 days ago
JSON representation
Generate and maintain stubs for different MicroPython ports to use with VSCode and Pylance, PyRight, Thonny, PyCharm or MyPy
- Host: GitHub
- URL: https://github.com/josverl/micropython-stubber
- Owner: Josverl
- License: other
- Created: 2019-03-26T16:00:53.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-01-16T23:35:15.000Z (5 days ago)
- Last Synced: 2025-01-17T00:26:09.999Z (5 days ago)
- Topics: firmware-stubs, micropython, micropython-stubber, micropython-stubs, mypy, mypy-stubs, pylance, pyright, python, static-typing, typed, vscode
- Language: Python
- Homepage: https://micropython-stubber.readthedocs.io
- Size: 72.4 MB
- Stars: 194
- Watchers: 10
- Forks: 14
- Open Issues: 47
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Boost MicroPython productivity in VSCode
[![pypi version](https://badgen.net/pypi/v/micropython-stubber)](https://pypi.org/project/micropython-stubber/)
[![python versions](https://badgen.net/pypi/python/micropython-stubber)](https://badgen.net/pypi/python/micropython-stubber)
[![Black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black "Black badge")
[![Star on GitHub](https://img.shields.io/github/stars/josverl/micropython-stubber.svg?style=social)](https://github.com/josverl/micropython-stubber/stargazers)
[![All Contributors](https://img.shields.io/badge/all_contributors-19-green.svg?style=flat-square)](#Contributions)
[![pytest stubber](https://github.com/Josverl/micropython-stubber/actions/workflows/pytest.yml/badge.svg)](https://github.com/Josverl/micropython-stubber/actions/workflows/pytest.yml)
[![pytest mpflash](https://github.com/Josverl/micropython-stubber/actions/workflows/pytest_mpflash.yml/badge.svg)](https://github.com/Josverl/micropython-stubber/actions/workflows/pytest_mpflash.yml)
[![Documentation Status](https://readthedocs.org/projects/micropython-stubber/badge/?version=latest)](https://micropython-stubber.readthedocs.io/en/latest/?badge=latest "Document build status badge")
[![Open in VSCode](https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc
)](https://open.vscode.dev/josverl/micropython-stubber)
The 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.
![demo][]]
In order to achieve this a few things are needed:
1) Stub files for the native / enabled modules in the firmware using PEP 484 Type Hints
2) Specific configuration of the VSCode Python extensions
3) Specific configuration of Pylint [ Optional ]
4) 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 PyPI
This 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-[-]stubs --no-user --target ./typings`
- Install in a venv (after activating)
`pip install -U micropython-[-]stubs --no-user`Examples:
``` bash
pip install -U micropython-stm32-stubs# Install stubs for a specific version.
pip install -U micropython-esp32-stubs==1.20.0.*# Install stubs for a specific board.
pip install -U micropython-rp2-pico_w-stubs
```For more details how to use the stubs please refer to [the documentation on RTD](https://micropython-stubs.readthedocs.io/en/latest/20_using.html)
1. The sister-repo [**MicroPython-stubs**][stubs-repo] contains [all stubs][all-stubs] I 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.2. A second repo [micropy-stubs repo][stubs-repo2] maintained by BradenM, also contains stubs, but in a structure only used and distributed by the [micropy-cli](#using-micropy-cli) tool.
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 tool
``` bash
pip install micropython-stubber# go to your working folder
cd my_stub_folder
mkdir all-stubs# clone the micropython repo's and switch to a specific version
stubber clone --add-stubs
stubber switch v1.22.2# get the document stubs for the current version ( v1.18 )
stubber get-docstubs# get the frozen stubs for the current version ( v1.18 )
stubber get-frozen# get the core CPython compatibility stubs from PyPi
stubber get-core# Update the fallback stubs
stubber update-fallback#
ls all-stubs
dir all-stubs
```## Developing & testing
This is described in more detail in the [developing](docs/developing.md) and [testing](docs/testing.md) documents in the docs folder.
## Branch Main
The name of the default branch has been changed to `main`.
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:
``` bash
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a
```for more info see [**Renaming a branch**](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-branches-in-your-repository/renaming-a-branch#updating-a-local-clone-after-a-branch-name-changes)
## Licensing
Both `MicroPython-Stubber` and `mpflash` are licensed under the MIT license, and all contributions should follow this [LICENSE](LICENSE).
# Contributions
Jos 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
π»
shariltumin
π₯ β
Matt Trentini
π₯ β
Stewart Russell
π₯ β
Andrew Leech
π₯ β
Wouter van Ooijen
π₯ β
Shane Powell
π₯ β
Robert Hammelrath
π₯ β
Bg
π₯ β
Raul KompaΓ
π₯ β
garryp4
π₯ β
Shane Powell
π₯ β
Andy Piper
π₯ β
David Horton
π₯ β
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
----------------------------
--------------------------------
[stubs-repo]: https://github.com/Josverl/micropython-stubs
[stubs-repo2]: https://github.com/BradenM/micropy-stubs
[micropython-stubber]: https://github.com/Josverl/micropython-stubber
[micropython-stubs]: https://github.com/Josverl/micropython-stubs#micropython-stubs
[micropy-cli]: https://github.com/BradenM/micropy-cli
[using-the-stubs]: https://github.com/Josverl/micropython-stubs#using-the-stubs
[demo]: https://github.com/Josverl/micropython-stubber/blob/main/docs/img/demo.gif?raw=true "demo of writing code using the stubs"
[stub processing order]: https://github.com/Josverl/micropython-stubber/blob/main/docs/img/stuborder_pylance.png?raw=true "recommended stub processing order"
[naming-convention]: #naming-convention-and-stub-folder-structure
[all-stubs]: https://github.com/Josverl/micropython-stubs/blob/main/firmwares.md
[micropython]: https://github.com/micropython/micropython
[micropython-lib]: https://github.com/micropython/micropython-lib
[pycopy]: https://github.com/pfalcon/pycopy
[pycopy-lib]: https://github.com/pfalcon/pycopy-lib