Giter Club home page Giter Club logo

josverl / micropython-stubber Goto Github PK

View Code? Open in Web Editor NEW
153.0 8.0 13.0 72.99 MB

Generate and maintain stubs for different MicroPython ports to use with VSCode and Pylance, PyRight, Thonny, PyCharm or pylint

Home Page: https://micropython-stubber.readthedocs.io

License: Other

Python 67.08% Shell 0.02% PowerShell 0.59% Dockerfile 0.04% Jupyter Notebook 12.30% JavaScript 19.96%
micropython-stubs micropython-stubber firmware-stubs python micropython static-typing pyright pylance vscode mypy

micropython-stubber's Introduction

Boost MicroPython productivity in VSCode

pypi version python versions Black Star on GitHub All Contributors

pytest stubber pytest mpflash Documentation Status

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 [ 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-<port>[-<board>]stubs --no-user --target ./typings
  • Install in a venv (after activating) pip install -U micropython-<port>[-<board>]stubs --no-user

Examples:

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

  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 only used and distributed by the 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

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
stubber switch --version v1.18

# 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 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
Jos Verlinde

πŸ’» πŸ”¬ πŸ€” πŸ–‹ πŸ“š βœ”
Thonny, Python IDE for beginners
Thonny, Python IDE for beginners

πŸ€” πŸ”¬
MicroPython
MicroPython

πŸ”£ πŸ“š
pyright
pyright

πŸ”§
Boris Lovosevic
Boris Lovosevic

πŸ”£ πŸ“š
Paul Sokolovsky
Paul Sokolovsky

πŸ”£ πŸ“š
pycopy
pycopy

πŸ”£ πŸ“š
Pycom
Pycom

πŸš‡
Braden Mars
Braden Mars

πŸ› πŸ’» πŸ“š πŸ“¦
James Manners
James Manners

πŸ’» πŸ›
Patrick
Patrick

πŸ› πŸ’» πŸ“š
Paul m. p. P.
Paul m. p. P.

πŸ€” πŸ”¬
Edward K. Ream
Edward K. Ream

πŸ”Œ
Daryl Stultz
Daryl Stultz

πŸ“š
Keeping things together
Keeping things together

πŸ›
vbolshakov
vbolshakov

πŸ› πŸ“š
Mauro Riva
Mauro Riva

πŸ“ πŸ›
MathijsNL
MathijsNL

πŸ›
Callum Jacob Hays
Callum Jacob Hays

πŸ› βœ”
ZoltΓ‘n VΓΆrΓΆs
ZoltΓ‘n VΓΆrΓΆs

πŸ”£
vincent-l-j
vincent-l-j

πŸ“–
Egor Litvinov
Egor Litvinov

πŸ›
Sam Duke
Sam Duke

πŸ’»

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



Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.