Skip to main content

Micropython Project Management Tool with VSCode support, Linting, Intellisense, Dependency Management, and more!

Project description

Micropy Cli PyPI PyPI - Python Version Github - Test Micropy Cli Coverage Status

Micropy Cli is a project management/generation tool for writing Micropython code in modern IDEs such as VSCode. Its primary goal is to automate the process of creating a workspace complete with:

  • Linting compatible with Micropython
  • VSCode Intellisense
  • Autocompletion
  • Dependency Management
  • VCS Compatibility

Micropy Demo SVG

Getting Started

Installation

You can download and install the latest version of this software from the Python package index (PyPI) as follows:

pip install --upgrade micropy-cli

If applicable, you can test out a pre-release by executing:

pip install --upgrade --pre micropy-cli

Creating a Project

Creating a new project folder is as simple as:

  1. Executing micropy init <PROJECT NAME>
  2. Selecting which features to enable
  3. Selecting your target device/firmware
  4. Boom. Your workspace is ready.

Micropy Demo

Micropy Project Environment

When creating a project with micropy-cli, two special items are added:

  • A .micropy/ folder
  • A micropy.json file

The .micropy/ contains symlinks from your project to your $HOME/.micropy/stubs folder. By doing this, micropy can reference the required stub files for your project as relative to it, rather than using absolute paths to $HOME/.micropy. How does this benefit you? Thanks to this feature, you can feel free to push common setting files such as settings.json and .pylint.rc to your remote git repository. This way, others who clone your repo can achieve a matching workspace in their local environment.

Note: The generated .micropy/ folder should be IGNORED by your VCS. It is created locally for each environment via the micropy.json file.

The micropy.json file contains information micropy needs in order to resolve your projects required files when other clone your repo. Think of it as a package.json for micropython.

Cloning a Micropy Environment

To setup a Micropy environment locally, simply:

  • Install micropy-cli
  • Navigate to the project directory
  • Execute micropy

Micropy will automatically configure and install any stubs required by a project thanks to its micropy.json file.

Project Dependencies

While all modules that are included in your targeted micropython firmware are available with autocompletion, intellisense, and linting, most projects require external dependencies.

Currently, handling dependencies with micropython is a bit tricky. Maybe you can install a cpython version of your requirement? Maybe you could just copy and paste it? What if it needs to be frozen?

Micropy handles all these issues for you automatically. Not only does it track your project's dependencies, it keeps both requirements.txt and dev-requirements.txt updated, enables autocompletion/intellisense for each dep, and allows you to import them just as you would on your device.

This allows you to include your requirement however you want, whether that be as a frozen module in your custom built firmware, or simply in the /lib folder on your device.

Installing Packages

To add a package as a requirement for your project, run:

micropy install <PACKAGE_NAMES>

while in your project's root directory.

This will automatically execute the following:

  • Source PACKAGE_NAMES from pypi, as a url, or a local path
  • Retrieve the module/package and stub it, adding it to your local .micropy folder.
  • Add requirement to your micropy.json
  • Update requirements.txt

To install dev packages that are not needed on your device, but are needed for local development, add the --dev flag. This will do everything above except stub the requirement.

You can also install all requirements found in micropy.json/requirements.txt/dev-requirements.txt by executing micropy install without passing any packages. Micropy will automatically do this when setting up a local environment of an existing micropy project.

Example

Lets say your new project will depend on picoweb and blynklib. Plus, you'd like to use rshell to communicate directly with your device. After creating your project via micropy init, you can install your requirements as so:

Micropy Pkg Install Demo

Now you or anybody cloning your project can import those requirements normally, and have the benefits of all the features micropy brings:

Micropy Deps Demo

Stub Management

Stub files are the magic behind how micropy allows features such as linting, Intellisense, and autocompletion to work. To achieve the best results with MicropyCli, its important that you first add the appropriate stubs for the device/firmware your project uses.

Note: When working in a micropy project, all stub related commands will also be executed on the active project. (i.e if in a project and you run micropy stubs add <stub-name>, then that stub retrieved AND added to the active project.)

Adding Stubs

Adding stubs to Micropy is a breeze. Simply run: micropy stubs add <STUB_NAME> By sourcing micropy-stubs, MicroPy has several premade stub packages to choose from.

These packages generally use the following naming schema:

<device>-<firmware>-<version>

For example, running micropy stubs add esp32-micropython-1.11.0 will install the following:

  • Micropython Specific Stubs
  • ESP32 Micropython v1.11 Device Specific Stubs
  • Frozen Modules for both device and firmware

You can search stubs that are made available to Micropy via micropy stubs search <QUERY>

Alternatively, using micropy stubs add <PATH>, you can manually add stubs to Micropy. For manual stub generation, please see Josvel/micropython-stubber.

Creating Stubs

Using micropy stubs create <PORT/IP_ADDRESS>, MicropyCli can automatically generate and add stubs from any Micropython device you have on hand. This can be done over both USB and WiFi.

Note: For stub creation, micropy-cli has additional dependencies.

These can be installed by executing: pip install micropy-cli[create_stubs]

Viewing Stubs

To list stubs you have installed, simply run micropy stubs list.

To search for stubs for your device, use micropy stubs search <QUERY>.

See Also

Acknowledgements

Micropython-Stubber

Josvel/micropython-stubber

Josverl's Repo is full of information regarding Micropython compatibility with VSCode and more. To find out more about how this process works, take a look at it.

micropy-cli and micropy-stubs depend on micropython-stubber for its ability to generate frozen modules, create stubs on a pyboard, and more.

Project details


Download files

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

Source Distribution

micropy_cli-4.1.0b0.tar.gz (188.2 kB view details)

Uploaded Source

Built Distribution

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

micropy_cli-4.1.0b0-py3-none-any.whl (164.2 kB view details)

Uploaded Python 3

File details

Details for the file micropy_cli-4.1.0b0.tar.gz.

File metadata

  • Download URL: micropy_cli-4.1.0b0.tar.gz
  • Upload date:
  • Size: 188.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

File hashes

Hashes for micropy_cli-4.1.0b0.tar.gz
Algorithm Hash digest
SHA256 4dd2044f4898a352590a6586603584c12f7317aa4296a9425f836c00f70dd069
MD5 3a5d210152906a7e7bc68024744cd15e
BLAKE2b-256 b4212348d155db76f7f244da5e5817dcb10660b3c7d39c1048b99775a69054a1

See more details on using hashes here.

File details

Details for the file micropy_cli-4.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: micropy_cli-4.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 164.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

File hashes

Hashes for micropy_cli-4.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f352fda78671e0afc2288e6b3f55a5fd6031c81dce509cfdcdce5e48c1b5421
MD5 aab09e9f7e04a02fd90ce0ae7f3f22b7
BLAKE2b-256 6f6c59dd7bb0e1734e9cb06d5c8139d881fbc10539871a21ebfbbbb0d8b5aa6b

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