How do you declare the dependencies of your projects? #16250
Replies: 4 comments 2 replies
-
I'm also interested in what people are doing in this sort of space. I've been using VSCode with a Python 3.11 development environment alongside my project which has the Micropython (eg. mpremote), CI support, analysis (eg. mypy) and documentation (eg. Sphinx) tooling installed, as well as the standard Micropython stub libraries. I don't yet have any other Micropython dependencies yet, so I don't know what the best practice is here. For my project I've been writing Python .pyi stub files alongside the Micropython .py files which allows me to use Python's If I'm doing this I'd also like to distribute the .pyi files in a way that users of my library can make them available to the typing tools (eg. as a stubs package), but unsure of the best way to do this (I don't think I want to have a stub package include the Micropython files, for example, so blindly using the standard Python packaging tools probably isn't right). And there isn't much point if people can't load the stubs packages where they can be seen by the analysis tools. |
Beta Was this translation helpful? Give feedback.
-
You can use a dedicated folder (e.g., micropython_lib) to house stubs and libraries, populated via mip or pip. |
Beta Was this translation helpful? Give feedback.
-
I don't know if manifest.py sees much use outside frozen modules from micropython-lib, but it does include simple requirements handling. For example, from bundle-networking: metadata(
version="0.2.0",
description="Common networking packages for all network-capable deployments of MicroPython.",
)
require("mip")
require("ntptime")
require("ssl")
require("requests")
require("webrepl")
# Provide urequests (which just forwards to requests) for backwards
# compatibility.
require("urequests") If I had to knowingly touch a venv at any time in MicroPython daily use, I'd nope right out. |
Beta Was this translation helpful? Give feedback.
-
Could you provide your input to : using a pyproject.toml file one could specify both mip modules and developer dependencies in the same file. [project]
name = "micro-parrot"
version = "0.1.0"
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: MicroPython",
"License :: OSI Approved :: MIT License"
]
[tool.mpremote]
# mpremote mip install -r pyproject.toml
mip = [
"aiorepl",
"aioble==0.5.0",
"github:peterhinch/micropython-mqtt",
"github:scruss/micropython-SYN6988/syn6988.py",
]
[project.optional-dependencies]
# install to folder typings
# uv pip install -r pyproject.toml --extra stubs --target typings
stubs = [
"micropython-rp2-stubs"
] |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I know that package.json allows specifying dependencies, but how do you let your program analyzer or language server know about the packages it needs for the analysis?
These tools need type stubs for MicroPython builtins and stdlib (which are available at PyPI in several variants) and also the MicroPython modules you would download from micropython-lib or someone's GitHub project and copy to the /lib directory of your device. Are you populating a venv containing all these and directing the tools to use it? Are you mip-installing the packages to a folder and using this folder as input? Anything else?
Using a venv as input for program analysis tools is flexible, but it may feel too confusing for beginners. I recently started to like uv, which focuses on the declaration of the dependencies and allows keeping venv-s behind the curtain, but it can do this thanks to the advances regarding to Python project configuration formats.
What is (or could be) MicroPython's solution for declaring the dependencies of a project such that the program analysis tools understand this, and it wouldn't involve too much hassle from the user?
Beta Was this translation helpful? Give feedback.
All reactions