# MicroPython package template
[![Downloads](https://pepy.tech/badge/micropython-package-template)](https://pepy.tech/project/micropython-package-template)
![Release](https://img.shields.io/github/v/release/brainelectronics/micropython-package-template?include_prereleases&color=success)
![MicroPython](https://img.shields.io/badge/micropython-Ok-green.svg)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![codecov](https://codecov.io/github/brainelectronics/micropython-package-template/branch/main/graph/badge.svg)](https://app.codecov.io/github/brainelectronics/micropython-package-template)
[![CI](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml/badge.svg)](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml)
MicroPython PyPi package template project with auto deploy
---------------
## General
MicroPython PyPi package template with GitHub Action based testing and deploy
📚 The latest documentation is available at
[MicroPython Package Template ReadTheDocs][ref-rtd-micropython-package-template] 📚
<!-- MarkdownTOC -->
- [Installation](#installation)
- [Install required tools](#install-required-tools)
- [Setup](#setup)
- [Install package](#install-package)
- [General](#general)
- [Specific version](#specific-version)
- [Test version](#test-version)
- [Manually](#manually)
- [Upload files to board](#upload-files-to-board)
- [Usage](#usage)
- [Create a PyPi \(micropython\) package](#create-a-pypi-micropython-package)
- [Setup](#setup-1)
- [Create a distribution](#create-a-distribution)
- [Upload to PyPi](#upload-to-pypi)
- [Contributing](#contributing)
- [Unittests](#unittests)
- [Steps after using this template](#steps-after-using-this-template)
- [Credits](#credits)
<!-- /MarkdownTOC -->
## Installation
### Install required tools
Python3 must be installed on your system. Check the current Python version
with the following command
```bash
python --version
python3 --version
```
Depending on which command `Python 3.x.y` (with x.y as some numbers) is
returned, use that command to proceed.
```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
## Setup
### Install package
Connect the MicroPython device to a network (if possible)
```python
import network
station = network.WLAN(network.STA_IF)
station.active(True)
station.connect('SSID', 'PASSWORD')
station.isconnected()
```
#### General
Install the latest package version of this lib on the MicroPython device
```python
import mip
mip.install("github:brainelectronics/micropython-package-template")
```
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`
```python
import upip
upip.install('micropython-package-template')
```
#### Specific version
Install a specific, fixed package version of this lib on the MicroPython device
```python
import mip
# install a verions of a specific branch
mip.install("github:brainelectronics/micropython-package-template", version="feature/initial-implementation")
# install a tag version
mip.install("github:brainelectronics/micropython-package-template", version="0.6.0")
```
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
With `upip` always the latest available version will be installed.
```python
import upip
upip.install('micropython-package-template')
```
#### Test version
Install a specific release candidate version uploaded to
[Test Python Package Index](https://test.pypi.org/) on every PR on the
MicroPython device. If no specific version is set, the latest stable version
will be used.
```python
import mip
mip.install("github:brainelectronics/micropython-package-template", version="0.6.0-rc9.dev13")
```
For MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.
With `upip` always the latest available version will be installed.
```python
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')
```
See also [brainelectronics Test PyPi Server in Docker][ref-brainelectronics-test-pypiserver]
for a test PyPi server running on Docker.
### Manually
#### Upload files to board
Copy the module to the MicroPython board and import them as shown below
using [Remote MicroPython shell][ref-remote-upy-shell]
Open the remote shell with the following command. Additionally use `-b 115200`
in case no CP210x is used but a CH34x.
```bash
rshell --port /dev/tty.SLAB_USBtoUART --editor nano
```
Perform the following command inside the `rshell` to copy all files and
folders to the device
```bash
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 /pyboard
```
## Usage
```python
from 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)
```
## Create a PyPi (micropython) package
### Setup
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.
```bash
python3 -m venv .venv
source .venv/bin/activate
pip install twine
```
### Create a distribution
This 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][ref-pfalcon-picoweb-sdist-upip] and updated to be PEP8
conform.
```bash
python setup.py sdist
```
A new folder `dist` will be created. The [`sdist_upip`](sdist_upip.py) will be
used to create everything necessary.
### Upload to PyPi
**Be aware: [pypi.org][ref-pypi] and [test.pypi.org][ref-test-pypi] are different**
You can **NOT** login to [test.pypi.org][ref-test-pypi] with the
[pypi.org][ref-pypi] account unless you created the same on the other. See
[invalid auth help page of **test** pypi][ref-invalid-auth-test-pypi]
For testing purposes add `--repository testpypi` to
upload it to [test.pypi.org][ref-test-pypi]
```bash
twine upload dist/micropython-package-template-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORD
```
## Contributing
### Unittests
Run the unittests locally with the following command after installing this
package in a virtual environment
```bash
# create a report directory where all generated report files are placed
python create_report_dirs.py
```
```bash
# run all tests
nose2 --config tests/unittest.cfg
# run only one specific tests
nose2 tests.test_blink.TestBlink.test_flash_led
```
Generate the coverage files with
```bash
coverage html
```
The coverage report is placed at `reports/coverage/html/index.html`
## Steps after using this template
In order to use this template for a new MicroPython package to following steps
should be done and changes to these file being made
| File | Changes | More details |
| ---- | ------- | -------------|
| `.coveragerc` | Path to `version.py` file | Omit version file from coverage |
| `.coveragerc` | Path to `include` folder | Include the package folder for coverage |
| `.github/workflows/release.yml` | Path to `version.py` file | Use package version file to set changelog based version |
| `.github/workflows/test-release.yml` | Path to `version.py` file | Use package version file to set changelog based version |
| `.github/workflows/test.yml` | Path to `version.py` file | Use package version file to set changelog based version |
| `.pre-commit-config.yaml` | Path to `version.py` file | Use package version file for validation against latest changelog based version |
| `README.md` | Links in header section and installation instructions | |
| `changelog.md` | Cleanup changelog from informations of template | Keep usage of SemVer |
| `docs/DOCUMENTATION.md` | Kink to ReadTheDocs | |
| `docs/conf.py` | List to modules to be mocked, package import, path to `version.py` file, update `author`, `project` and `linkcheck_ignore` | |
| `docs/index.rst` | Header name and included modules | Replace `be_upy_blink` with new `.rst` file of new package |
| `docs/NEW_MODULE_NAME.rst` | Create a new `.rst` file named as the package | Use `docs/be_upy_blink.rst` as template |
| `package.json` | Files and paths to new package and repo | Used by `mip` |
| `setup.py` | Path to `version.py` file, `name`, `description`, `url`, `author`, `author_email`, `keywords`, `project_urls`, `packages`, `install_requires` | Used to create the package and its informations published at e.g. PyPI |
## Credits
Based on the [PyPa sample project][ref-pypa-sample].
<!-- Links -->
[ref-rtd-micropython-package-template]: https://micropython-package-template.readthedocs.io/en/latest/
[ref-remote-upy-shell]: https://github.com/dhylands/rshell
[ref-brainelectronics-test-pypiserver]: https://github.com/brainelectronics/test-pypiserver
[ref-pypa-sample]: https://github.com/pypa/sampleproject
[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py
[ref-test-pypi]: https://test.pypi.org/
[ref-pypi]: https://pypi.org/
[ref-invalid-auth-test-pypi]: https://test.pypi.org/help/#invalid-auth
Raw data
{
"_id": null,
"home_page": "https://github.com/brainelectronics/micropython-package-template",
"name": "micropython-package-template",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "micropython, template, package",
"author": "brainelectronics",
"author_email": "info@brainelectronics.de",
"download_url": "https://files.pythonhosted.org/packages/e8/15/9216791b650e0a7190dbd7d5bdbe483f4cc9ed7057d70570023f6853683d/micropython-package-template-0.10.0.tar.gz",
"platform": null,
"description": "# MicroPython package template\n\n[![Downloads](https://pepy.tech/badge/micropython-package-template)](https://pepy.tech/project/micropython-package-template)\n![Release](https://img.shields.io/github/v/release/brainelectronics/micropython-package-template?include_prereleases&color=success)\n![MicroPython](https://img.shields.io/badge/micropython-Ok-green.svg)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/github/brainelectronics/micropython-package-template/branch/main/graph/badge.svg)](https://app.codecov.io/github/brainelectronics/micropython-package-template)\n[![CI](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml/badge.svg)](https://github.com/brainelectronics/micropython-package-template/actions/workflows/release.yml)\n\nMicroPython PyPi package template project with auto deploy\n\n---------------\n\n## General\n\nMicroPython PyPi package template with GitHub Action based testing and deploy\n\n\ud83d\udcda The latest documentation is available at\n[MicroPython Package Template ReadTheDocs][ref-rtd-micropython-package-template] \ud83d\udcda\n\n<!-- MarkdownTOC -->\n\n- [Installation](#installation)\n\t- [Install required tools](#install-required-tools)\n- [Setup](#setup)\n\t- [Install package](#install-package)\n\t\t- [General](#general)\n\t\t- [Specific version](#specific-version)\n\t\t- [Test version](#test-version)\n\t- [Manually](#manually)\n\t\t- [Upload files to board](#upload-files-to-board)\n- [Usage](#usage)\n- [Create a PyPi \\(micropython\\) package](#create-a-pypi-micropython-package)\n\t- [Setup](#setup-1)\n\t- [Create a distribution](#create-a-distribution)\n\t- [Upload to PyPi](#upload-to-pypi)\n- [Contributing](#contributing)\n\t- [Unittests](#unittests)\n- [Steps after using this template](#steps-after-using-this-template)\n- [Credits](#credits)\n\n<!-- /MarkdownTOC -->\n\n## Installation\n\n### Install required tools\n\nPython3 must be installed on your system. Check the current Python version\nwith the following command\n\n```bash\npython --version\npython3 --version\n```\n\nDepending on which command `Python 3.x.y` (with x.y as some numbers) is\nreturned, use that command to proceed.\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\n\npip install -r requirements.txt\n```\n\n## Setup\n\n### Install package\n\nConnect the MicroPython device to a network (if possible)\n\n```python\nimport network\nstation = network.WLAN(network.STA_IF)\nstation.active(True)\nstation.connect('SSID', 'PASSWORD')\nstation.isconnected()\n```\n\n#### General\n\nInstall the latest package version of this lib on the MicroPython device\n\n```python\nimport mip\nmip.install(\"github:brainelectronics/micropython-package-template\")\n```\n\nFor MicroPython versions below 1.19.1 use the `upip` package instead of `mip`\n\n```python\nimport upip\nupip.install('micropython-package-template')\n```\n\n#### Specific version\n\nInstall a specific, fixed package version of this lib on the MicroPython device\n\n```python\nimport mip\n# install a verions of a specific branch\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"feature/initial-implementation\")\n# install a tag version\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"0.6.0\")\n```\n\nFor MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.\nWith `upip` always the latest available version will be installed.\n\n```python\nimport upip\nupip.install('micropython-package-template')\n```\n\n#### Test version\n\nInstall a specific release candidate version uploaded to\n[Test Python Package Index](https://test.pypi.org/) on every PR on the\nMicroPython device. If no specific version is set, the latest stable version\nwill be used.\n\n```python\nimport mip\nmip.install(\"github:brainelectronics/micropython-package-template\", version=\"0.6.0-rc9.dev13\")\n```\n\nFor MicroPython versions below 1.19.1 use the `upip` package instead of `mip`.\nWith `upip` always the latest available version will be installed.\n\n```python\nimport upip\n# overwrite index_urls to only take artifacts from test.pypi.org\nupip.index_urls = ['https://test.pypi.org/pypi']\nupip.install('micropython-package-template')\n```\n\nSee also [brainelectronics Test PyPi Server in Docker][ref-brainelectronics-test-pypiserver]\nfor a test PyPi server running on Docker.\n\n### Manually\n\n#### Upload files to board\n\nCopy the module to the MicroPython board and import them as shown below\nusing [Remote MicroPython shell][ref-remote-upy-shell]\n\nOpen the remote shell with the following command. Additionally use `-b 115200`\nin case no CP210x is used but a CH34x.\n\n```bash\nrshell --port /dev/tty.SLAB_USBtoUART --editor nano\n```\n\nPerform the following command inside the `rshell` to copy all files and\nfolders to the device\n\n```bash\nmkdir /pyboard/lib\nmkdir /pyboard/lib/be_upy_blink\n\ncp be_upy_blink/* /pyboard/lib/be_upy_blink\n\ncp examples/main.py /pyboard\ncp examples/boot.py /pyboard\n```\n\n## Usage\n\n```python\nfrom be_upy_blink import flash_led\nfrom machine import Pin\n\nled_pin = Pin(4, Pin.OUT)\n\nflash_led(pin=led_pin, amount=3)\n# flash_led(pin=led_pin, amount=3, on_time=1, off_time=3)\n```\n\n## Create a PyPi (micropython) package\n\n### Setup\n\nInstall the required python package with the following command in a virtual\nenvironment to avoid any conflicts with other packages installed on your local\nsystem.\n\n```bash\npython3 -m venv .venv\nsource .venv/bin/activate\n\npip install twine\n```\n\n### Create a distribution\n\nThis module overrides distutils (also compatible with setuptools) `sdist`\ncommand to perform pre- and post-processing as required for MicroPython's\nupip package manager. This script is taken from\n[pfalcon's picoweb][ref-pfalcon-picoweb-sdist-upip] and updated to be PEP8\nconform.\n\n```bash\npython setup.py sdist\n```\n\nA new folder `dist` will be created. The [`sdist_upip`](sdist_upip.py) will be\nused to create everything necessary.\n\n### Upload to PyPi\n\n**Be aware: [pypi.org][ref-pypi] and [test.pypi.org][ref-test-pypi] are different**\n\nYou can **NOT** login to [test.pypi.org][ref-test-pypi] with the\n[pypi.org][ref-pypi] account unless you created the same on the other. See\n[invalid auth help page of **test** pypi][ref-invalid-auth-test-pypi]\n\nFor testing purposes add `--repository testpypi` to\nupload it to [test.pypi.org][ref-test-pypi]\n\n```bash\ntwine upload dist/micropython-package-template-*.tar.gz -u PYPI_USERNAME -p PYPI_PASSWORD\n```\n\n## Contributing\n\n### Unittests\n\nRun the unittests locally with the following command after installing this\npackage in a virtual environment\n\n```bash\n# create a report directory where all generated report files are placed\npython create_report_dirs.py\n```\n\n```bash\n# run all tests\nnose2 --config tests/unittest.cfg\n\n# run only one specific tests\nnose2 tests.test_blink.TestBlink.test_flash_led\n```\n\nGenerate the coverage files with\n\n```bash\ncoverage html\n```\n\nThe coverage report is placed at `reports/coverage/html/index.html`\n\n## Steps after using this template\n\nIn order to use this template for a new MicroPython package to following steps\nshould be done and changes to these file being made\n\n| File | Changes | More details |\n| ---- | ------- | -------------|\n| `.coveragerc` | Path to `version.py` file | Omit version file from coverage |\n| `.coveragerc` | Path to `include` folder | Include the package folder for coverage |\n| `.github/workflows/release.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.github/workflows/test-release.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.github/workflows/test.yml` | Path to `version.py` file | Use package version file to set changelog based version |\n| `.pre-commit-config.yaml` | Path to `version.py` file | Use package version file for validation against latest changelog based version |\n| `README.md` | Links in header section and installation instructions | |\n| `changelog.md` | Cleanup changelog from informations of template | Keep usage of SemVer |\n| `docs/DOCUMENTATION.md` | Kink to ReadTheDocs | |\n| `docs/conf.py` | List to modules to be mocked, package import, path to `version.py` file, update `author`, `project` and `linkcheck_ignore` | |\n| `docs/index.rst` | Header name and included modules | Replace `be_upy_blink` with new `.rst` file of new package |\n| `docs/NEW_MODULE_NAME.rst` | Create a new `.rst` file named as the package | Use `docs/be_upy_blink.rst` as template |\n| `package.json` | Files and paths to new package and repo | Used by `mip` |\n| `setup.py` | Path to `version.py` file, `name`, `description`, `url`, `author`, `author_email`, `keywords`, `project_urls`, `packages`, `install_requires` | Used to create the package and its informations published at e.g. PyPI |\n\n## Credits\n\nBased on the [PyPa sample project][ref-pypa-sample].\n\n<!-- Links -->\n[ref-rtd-micropython-package-template]: https://micropython-package-template.readthedocs.io/en/latest/\n[ref-remote-upy-shell]: https://github.com/dhylands/rshell\n[ref-brainelectronics-test-pypiserver]: https://github.com/brainelectronics/test-pypiserver\n[ref-pypa-sample]: https://github.com/pypa/sampleproject\n[ref-pfalcon-picoweb-sdist-upip]: https://github.com/pfalcon/picoweb/blob/b74428ebdde97ed1795338c13a3bdf05d71366a0/sdist_upip.py\n[ref-test-pypi]: https://test.pypi.org/\n[ref-pypi]: https://pypi.org/\n[ref-invalid-auth-test-pypi]: https://test.pypi.org/help/#invalid-auth\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "MicroPython PyPi package template project with auto deploy",
"version": "0.10.0",
"project_urls": {
"Bug Reports": "https://github.com/brainelectronics/micropython-package-template/issues",
"Homepage": "https://github.com/brainelectronics/micropython-package-template",
"Source": "https://github.com/brainelectronics/micropython-package-template"
},
"split_keywords": [
"micropython",
" template",
" package"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e8159216791b650e0a7190dbd7d5bdbe483f4cc9ed7057d70570023f6853683d",
"md5": "db20f32fbf3b89aa84f9d6e906c0d598",
"sha256": "378999e0659d00e53fd5db5ef20cb05771529dfc70aca6cc169364366df8e25b"
},
"downloads": -1,
"filename": "micropython-package-template-0.10.0.tar.gz",
"has_sig": false,
"md5_digest": "db20f32fbf3b89aa84f9d6e906c0d598",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4338,
"upload_time": "2024-09-30T22:37:40",
"upload_time_iso_8601": "2024-09-30T22:37:40.128626Z",
"url": "https://files.pythonhosted.org/packages/e8/15/9216791b650e0a7190dbd7d5bdbe483f4cc9ed7057d70570023f6853683d/micropython-package-template-0.10.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-30 22:37:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "brainelectronics",
"github_project": "micropython-package-template",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"requirements": [],
"lcname": "micropython-package-template"
}