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, and build.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 tour make demo runs.

  • 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

braidword.parse_word

Permutation, purity, cycles, closing repeats

pure_braid

Ring words, turns, solid_word / ring_moves

annulus_braid

Lay a word as curves or points, read a word back

parametric_strand (strand_paths, sample_strands, SampledStrand), symmetric_braid.braid_word

Linking numbers, from a word or from yarns

linking

Alexander polynomial, Burau matrix

properties, braid.reduced_burau_generator

Compare braids, find similar ones

similarity

Braids by topology, and every way of making each

topology_catalog

A braid as neighbours swapping places round a ring: the step to other ways of making it

ring_program

A braid as a punchcard for the Jacquard lace machine

making.lace

A braid as moves on a kumihimo disk

making.disk

A braid as a sinnet on Ashley’s stand, found by searching

making.ashley

A sinnet from the shape it takes, as Ashley draws it

making.ashley.sinnet_from_shape

A shape as cells on a grid (square, diagonal, triangular), its outline

making.ashley.grid_shape, grid_outline

From a sinnet’s moves back to its shape

making.ashley.move_groups, shapes_from_moves

Which of the book’s sinnets a shape draws

solid_sinnets_catalog.DRAWN

A word’s repeating unit

pure_braid.repeating_unit

Yarn physics, a marudai, in Python

rope, form, marudai (ports of web/*.js)

Colours, Plotly play/pause controls

utils.PALETTE, utils.play_controls

A catalogue of braids

catalog.Entry, each catalogue’s CATALOG

Defaults and limits for the web page

web/_settings.py

The page in another language: a text by its English

web/i18n.js, web/locales/

Rules

  • One implementation. Do not copy code between modules, nor between Python and JavaScript. make duplicates checks 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.js does take_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, the CATALOGs), 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, CLEAR in marudai), and is written as that name, or derived from it, wherever it is used: CLEAR * THICK, never 2.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 | None for the rest. A parameter whose default is None, meaning “not given”, is Optional[X]. A parameter that takes None as a value of its own (with no default, or another default, as limit: int | None = 10000, None for no limit), a return, an attribute and an element type are X | 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.py checks 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.py checks the spelling.

  • Commit only what you mean to. git add named paths, never a whole directory: web/site/ and web/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 test runs 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-all runs every test, as CI does daily on every Python supported, and on demand (workflow_dispatch).

  • make test-changed runs only the tests touching code changed since they last ran (pytest-testmon).

  • make typecheck, make lint and make duplicates check types, style and code copied rather than shared, in Python and JavaScript.

  • .github/workflows/braid_studio.yml builds Braid Studio and makes a braid of every kind in a browser on every pull request touching braidpy or the page; on develop it 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:

  1. Merge develop into main.

  2. Set the version in pyproject.toml, and say what changed in CHANGELOG.md, its date in place of “unreleased”. The version is also in server.json (twice) and uv.lock (uv lock).

  3. 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 version pyproject.toml gives.

  4. 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.