Contributing & Quality Gates¶
This guide covers the practical workflow for extending AlgebraX, maintaining Golden Source recipes, and passing every CI gate locally.
1. Environment Setup¶
AlgebraX uses uv for dependency management and ruff, pyrefly, pytest, and zensical for verification and documentation.
# Sync runtime, dev, test, and docs dependency groups
uv sync --all-groups
# Install pre-commit hooks (auto-syncs Jupytext .py -> .ipynb recipes)
git config --local core.hooksPath .git/hooks
uvx pre-commit install
2. Adding a New Algebraic Structure (4-Step Checklist)¶
Whenever you introduce a new concrete 0-cell algebraic structure (class or canonical factory family), complete all four steps enforced by tests/algebrax/test_registry_invariants.py:
- AMDS Docstring (
EP-0002): - Use a raw triple-quoted docstring (
r"""...""") whenever LaTeX math appears. - Include
Algebraic Signature:,Carrier:,Operations:,Properties:, andApplications:sections (I-3). - Never reference internal
EP-XXXXidentifiers insidesrc/algebrax/ordocs/guide/. - Registry Entry (
src/algebrax/registry.py): - Register a
StructureEntryvia_make_entry(...)with reifiedprotocols=andlaws=types (I-1,I-4). - If the constructor requires arguments (
zero_arg=False), provide a canonicalexample=factory (I-5). - Verification Fixture (
src/algebrax/verification/_registry_bridge.py): - Add a
StructureFixtureand, if introducing a new protocol family, a verifier + negative Popper falsification test sopython -m algebrax verify <Name>empirically tests every declared protocol andLaw*witness (I-2). - Add a traceability row in
docs/verification.mdreferencing live*.py::test_*functions. - Non-0-Cell Exports:
- If an exported class is a carrier, 1-cell morphism/functor/sheaf, ideal, or solver rather than a 0-cell structure provider, classify it explicitly in
EXPLICIT_EXCLUSIONSintests/algebrax/test_registry_invariants.py.
3. Golden Source Recipes & Jupytext Sync¶
All recipes in recipes/ are authored as Python scripts (.py) using Jupytext Percent format (# %% cell markers) with PEP 723 inline script metadata as the canonical Golden Source. Corresponding Jupyter Notebooks (.ipynb) are generated from those scripts — never edit .ipynb files by hand.
# Sync a single recipe script to its notebook
uvx jupytext --to notebook recipes/tropical_algebraic_curves.py
# Sync all recipes
uvx jupytext --to notebook recipes/*.py
# Execute a notebook as a test via nbmake
uv run --group test pytest --nbmake recipes/tropical_algebraic_curves.ipynb -v
4. Coding & Documentation Style¶
- Python Style: Max line length
120, single quotes for strings, double quotes for docstrings and f-strings (enforced byruff). - Immutability & Safety (
EP-0254): - Return defensive copies for exposed mutable dictionaries (e.g.,
.poly, sparse carriers). - Expose structural parameters (
n_vars,semiring,tol,field) as read-only@propertyaccessors. - Validate
NaN, non-finite bounds,boolpassed asint, and dimension/arity mismatches eagerly. - Escape all dynamic values in
_repr_html_()viahtml.escape(). - User Guide vs. Development Docs:
- Keep
docs/guide/strictly user-facing — zeroEP-XXXXIDs or roadmap phase labels. - Author architectural proposals under
docs/proposals/EP-XXXX-*.md, register them indocs/eps.md, and validate frontmatter/structure before promotion toFinal.
5. Local Quality Gates¶
Run all gates before opening a PR or cutting a release:
# 1. Lint & formatting
ruff check src/ tests/ recipes/
ruff format --check src/ tests/ recipes/
# 2. Static type checking
pyrefly check src/algebrax/
# 3. Architecture, hygiene & registry invariants (fast)
pytest tests/algebrax/test_hygiene.py tests/algebrax/test_registry_invariants.py -v
# 4. Full unit, property & differential test suite
pytest tests/ -q
# 5. Recipe notebook execution
pytest --nbmake recipes/ -q
# 6. CLI structure verification across all 100 registered structures
python -m algebrax verify --all
# 7. Static documentation site build (must report "No issues found")
zensical build
6. Commit & Release Workflow¶
AlgebraX uses Conventional Commits with commitizen (feat:, fix:, docs:, test:, refactor:, chore:).