MicroPython PyPi package template project with auto deploy
MicroPython PyPi package template with GitHub Action based testing and deploy
Python3 must be installed on your system. Check the current Python version with the following command
python --version python3 --versionDepending on which command Python 3.x.y (with x.y as some numbers) is returned, use that command to proceed.
python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txtConnect the MicroPython device to a network (if possible)
import network station = network.WLAN(network.STA_IF) station.connect('SSID', 'PASSWORD') station.isconnected()Install the latest package version of this lib on the MicroPython device
import upip upip.install('micropython-package-template')Install a specific, fixed package version of this lib on the MicroPython device
import upip upip.install('micropython-package-template==0.1.1')Install a specific release candidate version uploaded to Test Python Package Index on every PR on the MicroPython device. If no specific version is set, the latest stable version will be used.
import upip # overwrite index_urls to only take artifacts from test.pypi.org upip.index_urls = ['https://test.pypi.org/pypi'] upip.install('micropython-package-template==0.2.0rc1.dev6')See also brainelectronics Test PyPi Server in Docker for a test PyPi server running on Docker.
Copy the module to the MicroPython board and import them as shown below using Remote MicroPython shell
Open the remote shell with the following command. Additionally use -b 115200 in case no CP210x is used but a CH34x.
rshell --port /dev/tty.SLAB_USBtoUART --editor nanoPerform the following command inside the rshell to copy all files and folders to the device
mkdir /pyboard/lib mkdir /pyboard/lib/be_upy_blink cp be_upy_blink/* /pyboard/lib/be_upy_blink cp examples/main.py /pyboard cp examples/boot.py /pyboardfrom be_upy_blink import flash_led from machine import Pin led_pin = Pin(4, Pin.OUT) flash_led(pin=led_pin, amount=3) # flash_led(pin=led_pin, amount=3, on_time=1, off_time=3)Install the required python package with the following command in a virtual environment to avoid any conflicts with other packages installed on your local system.
python3 -m venv .venv source .venv/bin/activate pip install twineThis module overrides distutils (also compatible with setuptools) sdist command to perform pre- and post-processing as required for MicroPython's upip package manager. This script is taken from pfalcon's picoweb and updated to be PEP8 conform.
python setup.py sdistA new folder dist will be created. The sdist_upip will be used to create everything necessary.
Be aware: pypi.org and test.pypi.org are different
You can NOT login to test.pypi.org with the pypi.org account unless you created the same on the other. See invalid auth help page of test pypi
For testing purposes add --repository testpypi to upload it to test.pypi.org
twine upload dist/micropython-package-template-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORDRun the unittests locally with the following command after installing this package in a virtual environment
# run all tests nose2 --config tests/unittest.cfg # run only one specific tests nose2 tests.test_blink.TestBlink.test_flash_ledGenerate the coverage files with
python create_report_dirs.py coverage htmlThe coverage report is placed at reports/coverage/html/index.html
Based on the PyPa sample project.