A script builds the Debian package for the Cardputer Zero's app store

scripts/cardputer-zero/build-deb.sh runs on arm64 Debian 13 (the
Cardputer itself) and makes meshterm_<version>-<revision>_arm64.deb.
MeshTerm and all its Python packages, the spi extra included, go in
/usr/lib/meshterm, compiled to bytecode. The package depends only on
python3: the store app installs a missing dependency with apt-get but
never runs apt-get update, so a Debian dependency can fail. For the
same reason the package carries Terminus beside its OFL, because an app
from the launcher has no terminal for --fetch-fonts.

packaging/notices.py gets a site-directory mode, because the walk of
the closure asks for no extras and so misses the spi packages.

scripts/cardputer-zero/store holds the listing that czdev publish reads
and a 256-pixel icon. The screenshots are still to make.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5.5 committed 2026-10-07 02:39:27 -04:00
1 parent 93ed530fd7
commit 0b764e4a04
9 files changed
+289 -17

No files matched your search

+4 -2
View File
@@ -781,8 +781,10 @@ branch on the platform per frame, and never `from meshterm.platforms import PLAT
(`emulator/framebuffer.py`, written ahead of the hardware), a Tk window on the desktop
(`emulator/window.py`). The window is the **emulator** for both handhelds —
`meshterm emulate cardputer-zero|picocalc-lyra --mock`, after `meshterm emulate
--fetch-fonts` once (Terminus is OFL, so it is fetched and digest-checked, never
shipped). An `EmulatedDevice` (`emulator/devices.py`) is everything that differs per
--fetch-fonts` once (Terminus is OFL, so it is fetched and digest-checked, never in the
repo or the wheel; the store `.deb`, `scripts/cardputer-zero/build-deb.sh`, carries it
beside `OFL.TXT`, since a launcher app has no terminal to fetch it from — JP,
2026-10-07: "minimize potential problems"). An `EmulatedDevice` (`emulator/devices.py`) is everything that differs per
handheld: the panel, a Linux console's top-left grid and bold-as-bright 4-bit palette
(the PicoCalc), the lane keys drawn under the panel (the Cardputer's 4–8), and how its
keyboard spells Shift+F-keys. It is **not a strict emulator** — it mimics the display's
+5 -3
View File
@@ -63,7 +63,8 @@ draws each character on the display itself and reads the keys directly.
**Not done:**
- A package for M5Stack's app store. Until there is one, you install MeshTerm
- MeshTerm in M5Stack's app store. `scripts/cardputer-zero/build-deb.sh` builds the
package, but the store does not have it yet. Until it does, you install MeshTerm
yourself (refer to the next section).
- Typing on the real keyboard. Key events for the arrows, Enter, Esc, Fn+4 to Fn+8, and
Shift were sent to the keyboard from another computer. They worked. The symbols on the
@@ -93,8 +94,9 @@ python3 -m venv .venv
scripts/cardputer-zero/launcher-entry.sh
```
MeshTerm now has an icon in the launcher. To remove the icon, run
`scripts/cardputer-zero/launcher-entry.sh remove`.
MeshTerm now has an icon in the launcher. The icon is a negative of the MeshTerm logo. Thus
it is different from the icon of MeshTerm from the app store, and you can have both. To
remove the icon, run `scripts/cardputer-zero/launcher-entry.sh remove`.
### Typing long text from your computer
+4 -1
View File
@@ -1,7 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
"""Download the Terminus 12-pixel fonts that the emulator draws in: one time, only on request.
Terminus has the SIL Open Font License. Thus MeshTerm never ships it. This module
Terminus has the SIL Open Font License. Thus the repository and the wheel never carry it.
The Debian package for the Cardputer Zero carries it next to its licence, because an app
from the launcher has no terminal in which to run this download. That build also uses
this module (refer to ``scripts/cardputer-zero/build-deb.sh``). This module
downloads the upstream release and checks that it is the correct archive. Then it
extracts ``ter-u12n.bdf``, ``ter-u12b.bdf``, and the licence next to them into the
directory that the emulator reads (:func:`~.font.font_dir`). ``meshterm emulate
+38 -10
View File
@@ -36,7 +36,7 @@ import builtins
import platform
import sys
from dataclasses import dataclass
from importlib.metadata import Distribution, PackagePath, distribution
from importlib.metadata import Distribution, PackagePath, distribution, distributions
from pathlib import Path
from packaging.markers import default_environment
@@ -318,16 +318,41 @@ def dependency_closure(root: str = ROOT_DISTRIBUTION) -> list[Distribution]:
return sorted(seen.values(), key=lambda d: canonicalize_name(d.metadata["Name"]))
def collect_notices(root: str = ROOT_DISTRIBUTION) -> list[Notice]:
def installed_in(site: str | Path, root: str = ROOT_DISTRIBUTION) -> list[Distribution]:
"""Each distribution installed in the directory ``site``, except ``root``.
The Debian package for the Cardputer Zero installs MeshTerm with ``pip install
--target`` (refer to ``scripts/cardputer-zero/build-deb.sh``). Thus that directory holds
exactly the distributions that the package bundles. They include the ``spi`` extra,
which :func:`dependency_closure` does not follow, because it asks for no extras. The
directory is the true list, so this function reads it and does not walk requirements.
Returns:
The distributions, in the order of their canonical (PEP 503) name, as
:func:`dependency_closure` returns them.
"""
found = {canonicalize_name(d.metadata["Name"]): d for d in distributions(path=[str(site)])}
found.pop(canonicalize_name(root), None)
return [found[key] for key in sorted(found)]
def collect_notices(root: str = ROOT_DISTRIBUTION, site: str | Path | None = None) -> list[Notice]:
"""All the notices that ``THIRD-PARTY-NOTICES.txt`` of this build must carry.
The PSF notice of Python is always first. Python is not a PyPI distribution that
``Requires-Dist`` can name, so it can never appear in :func:`dependency_closure`. Each
dependency follows it, in the order of its name. Thus the difference between the notices
file of one build and the next is stable, and a person can examine it.
Args:
root: The distribution that the build ships.
site: A directory that ``pip install --target`` filled. If it is given, the
dependencies are the distributions in it (:func:`installed_in`). If it is
``None``, they are the closure of ``root`` in this interpreter.
"""
notices = [_python_notice()]
for dist in dependency_closure(root):
bundled = dependency_closure(root) if site is None else installed_in(site, root)
for dist in bundled:
canonical = canonicalize_name(dist.metadata["Name"])
notices.append(
Notice(
@@ -364,29 +389,32 @@ def render(notices: list[Notice]) -> str:
return "\n".join(blocks).rstrip("\n") + "\n"
def write_third_party_notices(path: str | Path, root: str = ROOT_DISTRIBUTION) -> Path:
def write_third_party_notices(
path: str | Path, root: str = ROOT_DISTRIBUTION, site: str | Path | None = None
) -> Path:
r"""Generate ``THIRD-PARTY-NOTICES.txt`` and write it to ``path``.
The function writes raw UTF-8 bytes. It does not use text mode. Thus a Windows build
does not change the ``\n`` line endings to ``\r\n``. The content of the file must be the
same, byte for byte, on each platform that builds it.
same, byte for byte, on each platform that builds it. ``site`` has the meaning that
:func:`collect_notices` gives it.
Returns:
``path``, as a :class:`~pathlib.Path`, for the convenience of the caller.
"""
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(render(collect_notices(root)).encode("utf-8"))
path.write_bytes(render(collect_notices(root, site)).encode("utf-8"))
return path
def main(argv: list[str] | None = None) -> int:
"""CLI entry point: ``python packaging/notices.py OUTPUT_PATH``."""
"""CLI entry point: ``python packaging/notices.py OUTPUT_PATH [SITE_DIR]``."""
args = sys.argv[1:] if argv is None else argv
if len(args) != 1:
print("usage: notices.py OUTPUT_PATH", file=sys.stderr)
if len(args) not in (1, 2):
print("usage: notices.py OUTPUT_PATH [SITE_DIR]", file=sys.stderr)
return 2
written = write_third_party_notices(args[0])
written = write_third_party_notices(args[0], site=args[1] if len(args) == 2 else None)
print(f"wrote {written}")
return 0
+1 -1
View File
@@ -5,7 +5,7 @@ These are tools for the repository. None of them is in the wheel.
| Script | What it is for |
|---|---|
| `basemap-doctor.py` | Finds why a user's map has no basemap: certificates, DNS, proxy, or colour depth |
| `cardputer-zero/` | `launcher-entry.sh` puts a source checkout in the Cardputer Zero's app launcher. `remove` takes it out. This is for the time before there is a store package. `meshterm.png` is the icon: the website's logo, at the launcher's 100×100 size. `type-text.py` types a pasted string (an API key, a Wi-Fi password) on the Cardputer's keyboard from another computer, over SSH |
| `cardputer-zero/` | `build-deb.sh` builds the Debian package for M5Stack's app store. Run it on the Cardputer Zero or on another arm64 Debian 13 system. `store/` holds the listing for the store (`app-builder.json`, which `czdev publish` reads) and its icon. `launcher-entry.sh` puts a source checkout in the Cardputer Zero's app launcher. `remove` takes it out. `meshterm.png` is the package's icon: the website's logo, at the launcher's 100×100 size. `meshterm-dev.png` is its negative, for the checkout's entry, so that the two entries look different. `type-text.py` types a pasted string (an API key, a Wi-Fi password) on the Cardputer's keyboard from another computer, over SSH |
| `picocalc-lyra/` | Setup of the Calculinux device: console font, palette, Wi-Fi. `xiao-radio/` is the kit for the XIAO radio (firmware build, flashing, UART setup) |
| `uconsole/` | The uConsole's always-on SPI bridge service. MeshTerm can also control that radio directly, with no script (refer to `docs/devices/uconsole.md`) |
+171
View File
@@ -0,0 +1,171 @@
#!/bin/sh
# SPDX-License-Identifier: Apache-2.0
# build-deb -- build the Debian package of MeshTerm for the Cardputer Zero's app store.
#
# Usage: scripts/cardputer-zero/build-deb.sh [REVISION]
#
# Run it on arm64 Debian 13 ("Trixie") with Python 3.13: on the Cardputer Zero itself, or
# in a debian:trixie container on an arm64 machine. The package holds compiled code
# (spidev, pycryptodome, and others), so it must be built on the system that it is for.
# Build it from a clean checkout of a release tag. pip builds MeshTerm from this tree, and
# it also takes the files in meshterm/ that git does not track. On the Cardputer Zero, /tmp
# is in memory and too small for the build: set TMPDIR to a directory on the card.
#
# The package depends only on python3. All else is inside it:
#
# /usr/lib/meshterm/site MeshTerm and its Python packages, compiled to bytecode
# /usr/lib/meshterm/fonts Terminus 6x12, regular and bold, and its licence (the OFL)
# /usr/share/APPLaunch/ the launcher entry, its icon, and the wrapper that it runs
# /usr/bin/meshterm the command line, for a user on SSH
# /usr/share/doc/meshterm/ LICENSE, NOTICE, THIRD-PARTY-NOTICES.txt, and copyright
#
# We add no other Debian dependency on purpose. When a dependency is not installed, the
# store app runs `apt-get install`, but it never runs `apt-get update`. On a device with
# old package lists, that install can fail. For the same reason the package carries the
# font: Terminus is not in the repository or in the wheel, but a launcher app has no
# terminal in which the user can run `meshterm emulate --fetch-fonts`.
#
# REVISION is the Debian revision, 1 by default. Increase it to publish a new package of
# the same MeshTerm version, because the store refuses a version that is not newer.
# Set TERMINUS_ARCHIVE to the path of terminus-font-4.49.1.tar.gz if the download fails.
# The build checks that archive against the same digest.
set -eu
umask 022
HERE=$(cd "$(dirname "$0")" && pwd)
SOURCE=$(cd "$HERE/../.." && pwd)
REVISION=${1:-1}
PYTHON=/usr/bin/python3
die() {
echo "build-deb: $*" >&2
exit 1
}
command -v dpkg-deb >/dev/null || die "no dpkg-deb here -- run this on Debian"
[ "$(dpkg --print-architecture)" = arm64 ] || die "this is not arm64 -- the package holds arm64 code"
[ "$("$PYTHON" -c 'import sys; print("%d.%d" % sys.version_info[:2])')" = 3.13 ] ||
die "$PYTHON is not Python 3.13 -- the package is for Debian 13"
case "$REVISION" in
*[!0-9]* | "") die "the revision must be a number, not '$REVISION'" ;;
esac
VERSION=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' "$SOURCE/meshterm/__init__.py")
[ -n "$VERSION" ] || die "no __version__ in $SOURCE/meshterm/__init__.py"
DEB_VERSION="$VERSION-$REVISION"
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
STAGE="$WORK/root"
LIB="$STAGE/usr/lib/meshterm"
DOC="$STAGE/usr/share/doc/meshterm"
APPLAUNCH="$STAGE/usr/share/APPLaunch"
echo "building meshterm $DEB_VERSION from $SOURCE"
# A venv for the tools of the build only. It has a current pip and the `packaging` library
# that packaging/notices.py imports. Its base is the system Python, so the compiled
# packages that its pip builds are correct for the Python that runs them.
"$PYTHON" -m venv "$WORK/venv"
"$WORK/venv/bin/pip" install --quiet --upgrade pip packaging
# MeshTerm and its packages, with the radio of the Cap LoRa-1262 (the `spi` extra).
# --no-compile, because the bytecode is compiled below in a different mode.
"$WORK/venv/bin/pip" install --quiet --no-compile --target "$LIB/site" "$SOURCE[spi]"
# pip writes console scripts whose first line names the build venv. The wrappers below
# replace them.
rm -rf "$LIB/site/bin"
# The licences: MeshTerm's own, and the licence of each package in the site directory.
mkdir -p "$DOC"
cp "$SOURCE/LICENSE" "$SOURCE/NOTICE" "$DOC/"
"$WORK/venv/bin/python" "$SOURCE/packaging/notices.py" "$DOC/THIRD-PARTY-NOTICES.txt" "$LIB/site"
cat >"$DOC/copyright" <<EOF
MeshTerm $VERSION
Source: https://github.com/jpmartineau/MeshTerm
MeshTerm is licensed under the Apache License, Version 2.0. Refer to LICENSE and NOTICE in
this directory. The name "MeshTerm" and its logo are trademarks. NOTICE has the terms.
The Python packages in /usr/lib/meshterm/site have their own licences. Refer to
THIRD-PARTY-NOTICES.txt in this directory.
The Terminus font in /usr/lib/meshterm/fonts is licensed under the SIL Open Font
License, Version 1.1. Refer to /usr/lib/meshterm/fonts/OFL.TXT.
EOF
# Terminus, downloaded and checked against its digest by meshterm.emulator.fetch.
MESHTERM_EMULATOR_FONTS="$LIB/fonts" PYTHONPATH="$LIB/site" "$PYTHON" -s -c '
import os, sys
from pathlib import Path
from meshterm.emulator.fetch import install_terminus
archive = os.environ.get("TERMINUS_ARCHIVE")
install_terminus(Path(archive) if archive else None)
'
# Bytecode. The user cannot write in /usr/lib, so Python cannot cache bytecode there at
# run time. Without this step, each start compiles all of MeshTerm again, and the start is
# several seconds slower. "unchecked-hash": the files never change after the install, so
# Python does not compare them with the source at each import.
"$PYTHON" -m compileall -q -j 0 --invalidation-mode unchecked-hash "$LIB/site" >/dev/null
# The wrappers. PYTHONPATH is exported, so that a child process of MeshTerm finds the same
# packages. -s keeps the packages of the user's own site directory out.
wrapper() {
cat >"$1" <<EOF
#!/bin/sh
# $2
export PYTHONPATH=/usr/lib/meshterm/site
export MESHTERM_EMULATOR_FONTS="\${MESHTERM_EMULATOR_FONTS:-/usr/lib/meshterm/fonts}"
exec /usr/bin/python3 -s -m $3 "\$@"
EOF
chmod 755 "$1"
}
mkdir -p "$STAGE/usr/bin" "$APPLAUNCH/bin" "$APPLAUNCH/applications" "$APPLAUNCH/share/images"
wrapper "$STAGE/usr/bin/meshterm" "MeshTerm's command line." meshterm
wrapper "$APPLAUNCH/bin/meshterm" "MeshTerm from the launcher: it draws on the display itself." meshterm.emulator
# The launcher entry. Terminal=false gives the app the display and the keyboard.
cat >"$APPLAUNCH/applications/meshterm.desktop" <<EOF
[Desktop Entry]
Name=MeshTerm
Exec=/usr/share/APPLaunch/bin/meshterm
Icon=share/images/meshterm.png
Terminal=false
Type=Application
EOF
install -m 644 "$HERE/meshterm.png" "$APPLAUNCH/share/images/meshterm.png"
# Make sure that the bundle runs before it is packaged: the help, a tool's help (the tools
# are found at run time), the written pages (the specimen), and the font of the display.
# MESHTERM_HOME keeps the files that a run writes out of the home directory of the builder.
check() {
MESHTERM_HOME="$WORK/home" MESHTERM_EMULATOR_FONTS="$LIB/fonts" PYTHONPATH="$LIB/site" \
"$PYTHON" -s "$@" >/dev/null
}
check -m meshterm --help
check -m meshterm contacts --help
check -m meshterm specimen
check -c 'from meshterm.emulator.font import find_font; find_font()'
mkdir -p "$STAGE/DEBIAN"
cat >"$STAGE/DEBIAN/control" <<EOF
Package: meshterm
Version: $DEB_VERSION
Architecture: arm64
Maintainer: Jean-Pierre Martineau <johnputer@meshterm.net>
Installed-Size: $(du -sk "$STAGE" | cut -f1)
Depends: python3 (>= 3.13), python3 (<< 3.14)
Section: hamradio
Priority: optional
Homepage: https://meshterm.net
Description: full-featured MeshCore client for the Cardputer Zero
MeshTerm is a full-featured TUI MeshCore client. On the Cardputer Zero it
draws on the display itself, and it runs the Cap LoRa-1262 as its own radio.
It can also connect to a companion over USB, Bluetooth, or TCP.
EOF
mkdir -p "$SOURCE/dist"
OUT="$SOURCE/dist/meshterm_${DEB_VERSION}_arm64.deb"
dpkg-deb --root-owner-group -Zxz --build "$STAGE" "$OUT" >/dev/null
echo "built $OUT ($(du -h "$OUT" | cut -f1))"
@@ -0,0 +1,35 @@
{
"package_name": "meshterm",
"app_name": "MeshTerm",
"bin_name": "meshterm",
"store": {
"summary": "A full-featured MeshCore client. Uses the Cap LoRa-1262 or a companion.",
"description": "MeshTerm is a full-featured MeshCore client. On the Cardputer Zero, it runs the Cap LoRa-1262 as its own radio, or it connects to a MeshCore companion over USB, Bluetooth, or TCP. Chat on channels and in direct messages, see the mesh on a map, trace paths, manage repeaters and rooms, and keep a record of every node heard. Fn+4 to Fn+8 drive the row of labels at the bottom of the display. Hold Esc to quit.",
"categories": [
"Radio & Comms"
],
"screenshots": [
"screenshots/menu.png",
"screenshots/chat.png",
"screenshots/map.png",
"screenshots/contacts.png"
],
"icon": "icon.png",
"license": "Apache-2.0",
"source_repo": "https://github.com/jpmartineau/MeshTerm",
"author": {
"github": "jpmartineau",
"display_name": "Jean-Pierre Martineau"
},
"share_code": "MTRM",
"permissions": {
"camera": false,
"microphone": false,
"imu": false,
"network": true,
"additional_hardware": true,
"background_service": false,
"external_display": false
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

+31
View File
@@ -165,3 +165,34 @@ def test_every_vendored_license_gap_has_its_file() -> None:
path = Path(notices.__file__).parent / rel
assert path.is_file(), f"{name}: {rel} is missing"
assert path.read_text(encoding="utf-8").strip(), f"{name}: {rel} is empty"
def _fake_dist(site: Path, name: str, version: str) -> None:
"""Write a minimal installed distribution with a licence file into ``site``."""
info = site / f"{name.replace('-', '_')}-{version}.dist-info"
info.mkdir(parents=True)
(info / "METADATA").write_text(
f"Metadata-Version: 2.1\nName: {name}\nVersion: {version}\nLicense-Expression: MIT\n",
encoding="utf-8",
)
(info / "LICENSE").write_text(f"The licence of {name}.\n", encoding="utf-8")
(info / "RECORD").write_text(
f"{info.name}/METADATA,,\n{info.name}/LICENSE,,\n{info.name}/RECORD,,\n",
encoding="utf-8",
)
def test_site_mode_lists_the_directory_and_not_the_closure(tmp_path: Path) -> None:
"""With ``site``, the notices are the distributions in that directory, less MeshTerm.
The Debian package for the Cardputer Zero bundles the ``spi`` extra. The walk of the
closure asks for no extras, so the package reads its ``pip install --target``
directory instead. The Python notice stays first in this mode too.
"""
_fake_dist(tmp_path, "mesh-term", "1.0")
_fake_dist(tmp_path, "zeta-lib", "2.0")
_fake_dist(tmp_path, "alpha-lib", "3.0")
got = notices.collect_notices(site=tmp_path)
assert [n.name for n in got] == ["Python", "alpha-lib", "zeta-lib"]
assert got[1].summary == "MIT"
assert "The licence of alpha-lib." in got[1].text