Package: micropython-package-template
MicroPython package templateMicroPython PyPi package template project with auto deployGeneralMicroPython PyPi package template with GitHub Action based testing and deploy📚 The latest documentation is available atMicroPython Package Template ReadTheDocs📚InstallationInstall required toolsSetupInstall packageGeneralSpecific versionTest versionManuallyUpload files to boardUsageCreate a PyPi (micropython) packageSetupCreate a distributionUpload to PyPiContributingUnittestsSteps after using this templateCreditsInstallationInstall required toolsPython3 must be installed on your system. Check the current Python version
with the following commandpython--version
python3--versionDepending on which commandPython 3.x.y(with x.y as some numbers) is
returned, use that command to proceed.python3-mvenv.venvsource.venv/bin/activate

pipinstall-rrequirements.txtSetupInstall packageConnect the MicroPython device to a network (if possible)importnetworkstation=network.WLAN(network.STA_IF)station.active(True)station.connect('SSID','PASSWORD')station.isconnected()GeneralInstall the latest package version of this lib on the MicroPython deviceimportmipmip.install("github:brainelectronics/micropython-package-template")For MicroPython versions below 1.19.1 use theupippackage instead ofmipimportupipupip.install('micropython-package-template')Specific versionInstall a specific, fixed package version of this lib on the MicroPython deviceimportmip# install a verions of a specific branchmip.install("github:brainelectronics/micropython-package-template",version="feature/initial-implementation")# install a tag versionmip.install("github:brainelectronics/micropython-package-template",version="0.6.0")For MicroPython versions below 1.19.1 use theupippackage instead ofmip.
Withupipalways the latest available version will be installed.importupipupip.install('micropython-package-template')Test versionInstall a specific release candidate version uploaded toTest Python Package Indexon every PR on the
MicroPython device. If no specific version is set, the latest stable version
will be used.importmipmip.install("github:brainelectronics/micropython-package-template",version="0.6.0-rc9.dev13")For MicroPython versions below 1.19.1 use theupippackage instead ofmip.
Withupipalways the latest available version will be installed.importupip# overwrite index_urls to only take artifacts from test.pypi.orgupip.index_urls=['https://test.pypi.org/pypi']upip.install('micropython-package-template')See alsobrainelectronics Test PyPi Server in Dockerfor a test PyPi server running on Docker.ManuallyUpload files to boardCopy the module to the MicroPython board and import them as shown below
usingRemote MicroPython shellOpen the remote shell with the following command. Additionally use-b 115200in case no CP210x is used but a CH34x.rshell--port/dev/tty.SLAB_USBtoUART--editornanoPerform the following command inside thershellto copy all files and
folders to the devicemkdir/pyboard/lib
mkdir/pyboard/lib/be_upy_blink

cpbe_upy_blink/*/pyboard/lib/be_upy_blink

cpexamples/main.py/pyboard
cpexamples/boot.py/pyboardUsagefrombe_upy_blinkimportflash_ledfrommachineimportPinled_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)Create a PyPi (micropython) packageSetupInstall 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-mvenv.venvsource.venv/bin/activate

pipinstalltwineCreate a distributionThis module overrides distutils (also compatible with setuptools)sdistcommand to perform pre- and post-processing as required for MicroPython's
upip package manager. This script is taken frompfalcon's picoweband updated to be PEP8
conform.pythonsetup.pysdistA new folderdistwill be created. Thesdist_upipwill be
used to create everything necessary.Upload to PyPiBe aware:pypi.organdtest.pypi.orgare differentYou canNOTlogin totest.pypi.orgwith thepypi.orgaccount unless you created the same on the other. Seeinvalid auth help page oftestpypiFor testing purposes add--repository testpypito
upload it totest.pypi.orgtwineuploaddist/micropython-package-template-*.tar.gz-uPYPI_USERNAME-pPYPI_PASSWORDContributingUnittestsRun the unittests locally with the following command after installing this
package in a virtual environment# create a report directory where all generated report files are placedpythoncreate_report_dirs.py# run all testsnose2--configtests/unittest.cfg# run only one specific testsnose2tests.test_blink.TestBlink.test_flash_ledGenerate the coverage files withcoveragehtmlThe coverage report is placed atreports/coverage/html/index.htmlSteps after using this templateIn order to use this template for a new MicroPython package to following steps
should be done and changes to these file being madeFileChangesMore details.coveragercPath toversion.pyfileOmit version file from coverage.coveragercPath toincludefolderInclude the package folder for coverage.github/workflows/release.ymlPath toversion.pyfileUse package version file to set changelog based version.github/workflows/test-release.ymlPath toversion.pyfileUse package version file to set changelog based version.github/workflows/test.ymlPath toversion.pyfileUse package version file to set changelog based version.pre-commit-config.yamlPath toversion.pyfileUse package version file for validation against latest changelog based versionREADME.mdLinks in header section and installation instructionschangelog.mdCleanup changelog from informations of templateKeep usage of SemVerdocs/DOCUMENTATION.mdKink to ReadTheDocsdocs/conf.pyList to modules to be mocked, package import, path toversion.pyfile, updateauthor,projectandlinkcheck_ignoredocs/index.rstHeader name and included modulesReplacebe_upy_blinkwith new.rstfile of new packagedocs/NEW_MODULE_NAME.rstCreate a new.rstfile  named as the packageUsedocs/be_upy_blink.rstas templatepackage.jsonFiles and paths to new package and repoUsed bymipsetup.pyPath toversion.pyfile,name,description,url,author,author_email,keywords,project_urls,packages,install_requiresUsed to create the package and its informations published at e.g. PyPICreditsBased on thePyPa sample project.