Skip to content

Commit 360ca9f

Browse files
authored
CI: Add support for MicroPython (#27)
1 parent 9bf1699 commit 360ca9f

File tree

8 files changed

+154
-11
lines changed

8 files changed

+154
-11
lines changed

.github/workflows/tests.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ jobs:
5151
pyproject.toml
5252
requirements*.txt
5353
54-
- name: Set up project tools
54+
- name: Set up project requirements and tools
5555
run: uv pip install --system --requirement=requirements.txt --requirement=requirements-dev.txt
5656

5757
- name: Run linters and software tests
58-
run: poe check
58+
run: poe check-cpython
5959

6060
# https://github.com/codecov/codecov-action
6161
- name: Upload coverage results to Codecov
@@ -68,3 +68,55 @@ jobs:
6868
env_vars: OS,PYTHON
6969
name: codecov-umbrella
7070
fail_ci_if_error: false
71+
72+
73+
test-micropython:
74+
name: "
75+
MicroPython ${{ matrix.micropython-version }}
76+
"
77+
runs-on: ${{ matrix.os }}
78+
strategy:
79+
fail-fast: false
80+
matrix:
81+
os: ['ubuntu-latest']
82+
micropython-version: [
83+
'v1.20.0',
84+
'v1.24.0',
85+
'v1.25.0-preview',
86+
]
87+
88+
env:
89+
OS: ${{ matrix.os }}
90+
MICROPYTHON: ${{ matrix.micropython-version }}
91+
92+
services:
93+
cratedb:
94+
image: crate/crate:nightly
95+
ports:
96+
- 4200:4200
97+
98+
steps:
99+
100+
- name: Acquire sources
101+
uses: actions/checkout@v4
102+
103+
- name: Set up CPython
104+
uses: actions/setup-python@v5
105+
with:
106+
python-version: '3.13'
107+
- name: Install uv
108+
uses: astral-sh/setup-uv@v3
109+
- name: Set up project tools
110+
run: uv pip install --system poethepoet
111+
112+
# https://github.com/marketplace/actions/install-micropython
113+
- name: Set up MicroPython ${{ matrix.micropython-version }}
114+
uses: BrianPugh/install-micropython@v2
115+
with:
116+
reference: ${{ matrix.micropython-version }}
117+
118+
- name: Set up project requirements
119+
run: micropython -m mip install base64 requests
120+
121+
- name: Run linters and software tests
122+
run: poe check-micropython

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,9 @@ Constants for each value of `code` are provided. For example `4043` is `CRATEDB
444444
## Examples
445445

446446
The [`examples`](examples/) folder contains example MicroPython scripts, some of which are for specific microcontroller boards, including the popular Raspberry Pi Pico W.
447-
Hardware-independent example programs also work well on CPython, see [Running on CPython](./docs/cpython.md).
447+
Hardware-independent example programs also work well on CPython, and the
448+
MicroPython UNIX and Windows port, see [Running on CPython](./docs/cpython.md)
449+
and [Running on MicroPython](./docs/micropython.md).
448450

449451
## Testing
450452

cratedb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def __make_request(self, sql, args=None, with_types=False, return_response=True)
129129
payload["bulk_args"] = args
130130

131131
try:
132-
response = requests.post(request_url, headers=headers, json=payload)
132+
response = requests.post(request_url, headers=headers, json=payload) # noqa: S113
133133
except OSError as o:
134134
raise NetworkError(o) # noqa: B904
135135

docs/cpython.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
The module is designed for [MicroPython], but also works on [CPython].
44

5+
While CPython does not provide hardware support usually available when
6+
running MicroPython on embedded devices, this is mostly not a concern
7+
when running a database driver.
8+
9+
510
## Setup
611

712
Install Python package and project manager [uv].

docs/micropython.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Running on MicroPython
2+
3+
The module is designed for [MicroPython]. You can run it on embedded systems,
4+
and, thanks to the [MicroPython UNIX and Windows port], also on Linux, macOS,
5+
and Windows.
6+
7+
While MicroPython on a workstation does not provide hardware support usually
8+
available when running MicroPython on embedded devices, this is mostly not
9+
a concern when running a database driver.
10+
11+
12+
## Embedded
13+
14+
Todo.
15+
16+
17+
## Workstation
18+
19+
### Setup
20+
21+
Install MicroPython.
22+
```shell
23+
{apt,brew,pip,zypper} install micropython
24+
```
25+
26+
Install requirements.
27+
```shell
28+
micropython -m mip install base64 requests
29+
```
30+
31+
## Usage
32+
33+
Start CrateDB.
34+
```shell
35+
docker run --rm -it --name=cratedb \
36+
--publish=4200:4200 --publish=5432:5432 \
37+
--env=CRATE_HEAP_SIZE=2g crate:latest -Cdiscovery.type=single-node
38+
```
39+
40+
Invoke example programs.
41+
```shell
42+
export MICROPYPATH=".frozen:${HOME}/.micropython/lib:/usr/lib/micropython:$(pwd)"
43+
micropython examples/example_usage.py
44+
micropython examples/object_examples.py
45+
```
46+
47+
48+
[MicroPython]: https://en.wikipedia.org/wiki/Micropython
49+
[MicroPython UNIX and Windows port]: https://docs.micropython.org/en/latest/unix/quickref.html

pyproject.toml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ exclude_lines = [
9090
[tool.poe.tasks]
9191

9292
check = [
93-
"lint",
94-
"test",
93+
"check-cpython",
94+
"check-micropython",
95+
]
96+
97+
check-cpython = [
98+
"lint-cpython",
99+
"test-cpython",
100+
]
101+
102+
check-micropython = [
103+
"test-micropython",
95104
]
96105

97106
format = [
@@ -102,18 +111,23 @@ format = [
102111
{ cmd = "pyproject-fmt --keep-full-version pyproject.toml" },
103112
]
104113

105-
lint = [
114+
lint-cpython = [
106115
{ cmd = "ruff format --check ." },
107116
{ cmd = "ruff check ." },
108117
{ cmd = "validate-pyproject pyproject.toml" },
109118
]
110119

111-
[tool.poe.tasks.test]
120+
[tool.poe.tasks."test-cpython"]
112121
cmd = "pytest"
113-
help = "Invoke software tests"
122+
help = "Invoke software tests on CPython"
114123

115-
[tool.poe.tasks.test.args.expression]
124+
[tool.poe.tasks."test-cpython".args.expression]
116125
options = [ "-k" ]
117126

118-
[tool.poe.tasks.test.args.marker]
127+
[tool.poe.tasks."test-cpython".args.marker]
119128
options = [ "-m" ]
129+
130+
[tool.poe.tasks."test-micropython"]
131+
sequence = [
132+
{ shell = 'MICROPYPATH="${HOME}/.micropython/lib:$(pwd)" micropython tests/test_micropython.py' },
133+
]
File renamed without changes.

tests/test_micropython.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# ruff: noqa: S605, S607
2+
import os
3+
4+
5+
def example_usage():
6+
"""
7+
Validate `examples/example_usage.py` runs to completion.
8+
"""
9+
assert os.system("micropython examples/example_usage.py") == 0
10+
11+
12+
def object_examples():
13+
"""
14+
Validate `examples/object_examples.py` runs to completion.
15+
"""
16+
assert os.system("micropython examples/object_examples.py") == 0
17+
18+
19+
if __name__ == "__main__":
20+
example_usage()
21+
object_examples()

0 commit comments

Comments
 (0)