Skip to main content

Tooling to create and maintain stubs for MicroPython

Project description

Boost MicroPython productivity in VSCode

pypi version python versions Documentation Status Star on GitHub All Contributors

Language grade: Python pytest tests/common codecov Black

Open in VSCode

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
  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 github or other means, so it is quite likely that you can just grab a copy be be productive in a few minutes.

For now you will need to configure this by hand, or use the micropy cli` tool

  1. The sister-repo MicroPython-stubs contains 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 maintained by BradenM, also contains stubs but in a structure used and distributed by the micropy-cli tool. you should use micropy-cli to consume stubs in this repo.

The (stretch) goal is to create a VSCode add-in to simplify the configuration, and allow easy switching between different firmwares and versions.

Developing & testing

This is described in more detail in the developing and testing 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:

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

Licensing

MicroPython-Stubber is licensed under the MIT license, and all contributions should follow this LICENSE.

Contributions


Jos Verlinde

๐Ÿ’ป ๐Ÿ”ฌ ๐Ÿค” ๐Ÿ–‹ ๐Ÿ“š โœ”

Thonny, Python IDE for beginners

๐Ÿค” ๐Ÿ”ฌ

MicroPython

๐Ÿ”ฃ ๐Ÿ“š

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

๐Ÿ”ฃ

This project follows the all-contributors specification. Contributions of any kind welcome!



Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micropython-stubber-1.6.0.tar.gz (65.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

micropython_stubber-1.6.0-py3-none-any.whl (69.9 kB view details)

Uploaded Python 3

File details

Details for the file micropython-stubber-1.6.0.tar.gz.

File metadata

  • Download URL: micropython-stubber-1.6.0.tar.gz
  • Upload date:
  • Size: 65.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.9.9 Windows/10

File hashes

Hashes for micropython-stubber-1.6.0.tar.gz
Algorithm Hash digest
SHA256 09f4c903271c0248e3fd9efee9412013c867335b6e598ed5b9ad00f7dc72e989
MD5 36170acc188c44c7b325279d508dc76b
BLAKE2b-256 cecd0b7591d3ca92268014507628e3320477f16062e5c67c782605bd08fbdc79

See more details on using hashes here.

File details

Details for the file micropython_stubber-1.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for micropython_stubber-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c0bbe89e6f55f487ed5a5d8727e84dc91c9eb69e02f9c8ce6e09e8f256d239d4
MD5 c8ecea3cc86730abbdd6eaa79bc8cdb0
BLAKE2b-256 220a6009461f0434dcef5d9522f361b5fb5da21cf6fe93e40681671d50d9e2f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page