Package: micropy-cli
Micropy CliMicropy Cli is a project management/generation tool for writingMicropythoncode in modern IDEs such as VSCode.
Its primary goal is to automate the process of creating a workspace complete with:Lintingcompatible with MicropythonVSCodeIntellisenseAutocompletionDependency ManagementVCS CompatibilityGetting StartedInstallationYou can download and install the latest version of this software from the Python package index (PyPI) as follows:pip install --upgrade micropy-cliIf applicable, you can test out a pre-release by executing:pip install --upgrade --pre micropy-cliCreating a ProjectCreating a new project folder is as simple as:Executingmicropy init <PROJECT NAME>Selecting which features to enableSelecting your target device/firmwareBoom. Your workspace is ready.Micropy Project EnvironmentWhen creating a project withmicropy-cli, two special items are added:A.micropy/folderAmicropy.jsonfileThe.micropy/contains symlinks from your project to your$HOME/.micropy/stubsfolder. 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 assettings.jsonand.pylint.rcto 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 beIGNOREDby your VCS. It is created locally for each environment via themicropy.jsonfile.Themicropy.jsonfile contains information micropy needs in order to resolve your projects required files when other clone your repo. Think of it as apackage.jsonfor micropython.Cloning a Micropy EnvironmentTo setup a Micropy environment locally, simply:Installmicropy-cliNavigate to the project directoryExecutemicropyMicropy will automatically configure and install any stubs required by a project thanks to itsmicropy.jsonfile.Project DependenciesWhile 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 bothrequirements.txtanddev-requirements.txtupdated, 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/libfolder on your device.Installing PackagesTo 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:SourcePACKAGE_NAMESfrom pypi, as a url, or a local pathRetrieve the module/package and stub it, adding it to your local.micropyfolder.Add requirement to yourmicropy.jsonUpdaterequirements.txtTo install dev packages that are not needed on your device, but are needed for local development, add the--devflag. This will do everything aboveexceptstub the requirement.You can also install all requirements found inmicropy.json/requirements.txt/dev-requirements.txtby executingmicropy installwithout passing any packages. Micropy will automatically do this when setting up a local environment of an existing micropy project.ExampleLets say your new project will depend onpicowebandblynklib. Plus, you'd like to usershellto communicate directly with your device. After creating your project viamicropy init, you can install your requirements as so:Now you or anybody cloning your project can import those requirements normally, and have the benefits of all the features micropy brings:Stub ManagementStub 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 runmicropy stubs add <stub-name>, then that stub retrieved AND added to the active project.)Adding StubsAdding stubs to Micropy is a breeze. Simply run:micropy stubs add <STUB_NAME>By sourcingmicropy-stubs, MicroPy has several premade stub packages to choose from.These packages generally use the following naming schema:<device>-<firmware>-<version>For example, runningmicropy stubs add esp32-micropython-1.11.0will install the following:Micropython Specific StubsESP32 Micropython v1.11 Device Specific StubsFrozen Modules for both device and firmwareYou can search stubs that are made available to Micropy viamicropy stubs search <QUERY>Alternatively, usingmicropy stubs add <PATH>, you can manually add stubs to Micropy.
For manual stub generation, please seeJosvel/micropython-stubber.Creating StubsUsingmicropy 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 StubsTo list stubs you have installed, simply runmicropy stubs list.To search for stubs for your device, usemicropy stubs search <QUERY>.See AlsoVSCode IntelliSense, Autocompletion & Linting capabilitiesAn awesome article written bylemariva. It covers creating a micropython project environment from scratch usingmicropy-cliandpymakr-vsc. Great place to start if you're new to this!Developing for the Raspberry Pi Pico in VS CodeA getting started guide for developing in micropython on the Raspberry Pi Pico bycpwood.Also see:Pico-Go: Micropy-CliAwesome MicroPythonCollection of awesome micropython libraries / resources.Featuresmicropy-clialong with several other great development tools under theDevelopmentcategory.AcknowledgementsMicropython-StubberJosvel/micropython-stubberJosverl'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 andmicropy-stubsdepend on micropython-stubber for its ability to generate frozen modules, create stubs on a pyboard, and more.