Developer guide
How braidpy is worked on: setting it up, the rules it is written by, its tests, its documentation and its releases. Braid Studio, the web page, has a page of its own: Braid Studio’s internals.
Setting up
From a clone of the repository (on the develop branch), with
uv, the project’s package manager:
make install-uv # uv itself, if missing
uv sync --all-extras --dev # braidpy, its extras and the tools to work on it
pre-commit install # format and lint each commit
make help # every target, with what it does
The project’s Python is in .python-version; every Python braidpy supports
is tested daily (see below). It is 3.12, a version everything installs on
without building from source; CI runs the quick tests on the newest Python
supported.
Where things are
src/braidpy/— the library. A module per idea; each module’s docstring says what it is for, and API reference lists them by area.web/— Braid Studio: the page, its workers, andbuild.py, which makes the site.tests/— pytest tests;tests/js/runs the page’s JavaScript in Node for them.docs/source/— these pages.examples/— short scripts using braidpy, and the console tourmake demoruns.scripts/— the documentation’s figures (gen_docs_figures.py) and the demo pages (gen_demos.py,gen_braid_geometry_demo.py), each run from the repository’s root.
How braidpy is written
These are the rules braidpy is worked on by, for people and for Claude
alike; they are kept in CLAUDE.md, at the root of the repository.
Before writing anything, look for it
Most things braidpy needs already exist somewhere in it. Search first (by
name and by idea: git grep, the module docstrings), and extend what is
there rather than write a second one. Places that have been rewritten by
mistake before:
Need |
Already in |
|---|---|
Read a braid word from text |
|
Permutation, purity, cycles, closing repeats |
|
Ring words, turns, |
|
Lay a word as curves or points, read a word back |
|
Linking numbers, from a word or from yarns |
|
Alexander polynomial, Burau matrix |
|
Compare braids, find similar ones |
|
Braids by topology, and every way of making each |
|
A braid as neighbours swapping places round a ring: the step to other ways of making it |
|
A braid as a punchcard for the Jacquard lace machine |
|
A braid as moves on a kumihimo disk |
|
A braid as a sinnet on Ashley’s stand, found by searching |
|
A sinnet from the shape it takes, as Ashley draws it |
|
A shape as cells on a grid (square, diagonal, triangular), its outline |
|
From a sinnet’s moves back to its shape |
|
Which of the book’s sinnets a shape draws |
|
A word’s repeating unit |
|
Yarn physics, a marudai, in Python |
|
Colours, Plotly play/pause controls |
|
A catalogue of braids |
|
Defaults and limits for the web page |
|
The page in another language: a text by its English |
|
Rules
One implementation. Do not copy code between modules, nor between Python and JavaScript.
make duplicateschecks both and runs in CI.JavaScript only where the browser needs speed. When a Python algorithm must also run in the page (as
web/tighten.jsdoestake_off.tighten_yarns), the Python is the reference and a test runs both and compares them (tests/test_tighten_js.py). Where the JavaScript came first, a Python port step for step is checked the same way, bead for bead with the maths library rounded alike (tests/js_maths.py;braidpy.marudai,braidpy.rope,braidpy.form): change one, change the other. JavaScript test cases run only what is JavaScript’s: geometry going in and checks coming out are done in Python, with braidpy (tests/test_rope.py).Documentation links, it does not restate. If a method is described on one page, other pages link to it and say only what differs.
Data apart from code. Defaults, limits, titles and catalogues are data (
web/_settings.py, theCATALOGs), not literals inside functions.No magic numbers. A number that means something (a size, a margin, a factor) gets a name and a comment saying what it is, once, beside its kin (
REACH,THICK,CLEARinmarudai), and is written as that name, or derived from it, wherever it is used:CLEAR * THICK, never2.2.A unit in the name, unless SI. A quantity in another unit carries it as a suffix:
bobbin_diameter_mm,mm_per_unit. One in the drawing’s own units, or in whatever unit it is given, says so in its docstring.Optional[X]for an optional argument,X | Nonefor the rest. A parameter whose default isNone, meaning “not given”, isOptional[X]. A parameter that takesNoneas a value of its own (with no default, or another default, aslimit: int | None = 10000, None for no limit), a return, an attribute and an element type areX | None.Refactoring keeps results. Check outputs are the same before and after (for
braidpy.web, the same JSON for every build); say so in the PR, and say what changes when something does.The page’s words are English, their French beside them. A sentence added to or changed on Braid Studio, in Python or in JavaScript, gets its line in
web/locales/fr.toml(a pattern for one with numbers or names in it);tests/test_i18n_js.pychecks the pages and catalogues.American spelling for names, prose as you like. Names braidpy defines, in Python and JavaScript, say
color,center,neighbor,catalog, as Python and its libraries do — no exceptions. Comments, docstrings and pages may be British. Strings and JSON keys are data and keep their spelling. A name renamed keeps its old one working, warning (braidpy._renamed), for the release that renames it and one more, and goes at the next;tests/test_spelling.pychecks the spelling.Commit only what you mean to.
git addnamed paths, never a whole directory:web/site/andweb/node_modules/are build output.
Before pushing
make lint && make typecheck && make test && make duplicates
make test is the quick run CI makes on every push: every test but those
marked slow, in parallel. make test-all runs the slow ones too, as CI
does daily; run it when a change touches what they test. make test-changed runs only the tests touching code changed since they last ran
(pytest-testmon). A test that takes seconds is marked
@pytest.mark.slow.
Code and comments are in English, with Google-style docstrings and type hints throughout.
Tests and CI
make testruns the quick tests, in parallel: every test but those marked@pytest.mark.slow, in a couple of minutes. CI runs them on every push.make test-allruns every test, as CI does daily on every Python supported, and on demand (workflow_dispatch).make test-changedruns only the tests touching code changed since they last ran (pytest-testmon).make typecheck,make lintandmake duplicatescheck types, style and code copied rather than shared, in Python and JavaScript..github/workflows/braid_studio.ymlbuilds Braid Studio and makes a braid of every kind in a browser on every pull request touching braidpy or the page; ondevelopit publishes the site.
Documentation
make docs builds these pages in docs/build/html, with Sphinx and MyST.
They are in three parts — the user manual, the theory manual and this
guide — and each page links to others rather than repeat them. The figures
are drawn by scripts/gen_docs_figures.py from braidpy’s own functions: change one,
draw them again. make doc-deploy publishes the pages to GitHub Pages, under
the branch’s name, or under the release’s tag from main.
Releasing
Releases are made by hand, from main:
Merge
developintomain.Set the version in
pyproject.toml, and say what changed inCHANGELOG.md, its date in place of “unreleased”. The version is also inserver.json(twice) anduv.lock(uv lock).Tag the release with its version (
git tag 0.4.0), as the earlier ones are, and push the tag: the release workflow (release.yml) builds the package and publishes it on PyPI, refusing a tag that is not the versionpyproject.tomlgives.Publish its documentation:
make doc-deploy.
A release is cut every two or three weeks while the API still moves: each
break costs less made sooner, and CHANGELOG.md is what the people using
braidpy read to follow it.