CM3D-006: Project tooling: cm3d package, uv, pre-commit and an Antora preview
Context
The runner for tests, STL export and doc pictures was a single loose script that used only the standard library. It had no unit tests, no pinned tool versions and no checks before a commit. It could already render the docs pictures and check that every picture a page refers to exists, but only as a script inside the repository, not as an installed command. The docs are an Antora component that will later join the main docs site of the software repository, but it could not be previewed on its own.
Decision
-
The runner is the Python package
cm3d(src/cm3d/) with the commandcm3d test|export|render, built with click. It has unit tests intests/python/(pytest). -
uv manages the Python version and the dependencies, and
uv.lockpins them. -
pre-commit runs the file hygiene hooks, codespell and ruff before every commit.
-
commitizen checks the commit messages (Conventional Commits) and offers
uv run cz commit. -
Pictures are rendered only on command (
cm3d render) and committed, so no hook renders them and the docs build without CAD tools.cm3d renderfails if a page refers to a picture that does not exist. -
antora-playbook.ymlandpackage.jsonbuild a preview of the component alone (npm run docs). The README shows the source entry that adds the component to the main playbook.
Alternatives considered
-
Single file with inline dependencies (PEP 723): Keeps one file, but the code grows beyond one screen and is harder to test and to split.
-
A hook that renders the pictures on commit: Takes minutes per commit, needs the CAD tools on every machine and changes files during the commit.
-
Plain Makefile or shell scripts: Not portable to Windows, which is the main platform here.
Consequences
-
Good: The runner is tested, and the tool versions are pinned.
-
Good: Broken files and badly worded commit messages are caught before they enter the history.
-
Good: The docs can be previewed alone and join the main site without changes to the pages.
-
Bad: Contributors need
uvand, for the docs preview, Node.js. -
Bad: The pictures can get out of date, because they have to be rendered again by hand after a change to the model.
-
Amended by CM3D-010: The runner now builds the build123d models:
cm3d test|export|render|mesh|bom, with tests intests/tools/andtests/common/and not intests/python/. The OpenSCAD runner described here has been removed with the OpenSCAD tree. See CM3D-010: Export, doc pictures and viewer: registries in Python.