Skip to content

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:

  1. AMDS Docstring (EP-0002):
  2. Use a raw triple-quoted docstring (r"""...""") whenever LaTeX math appears.
  3. Include Algebraic Signature:, Carrier:, Operations:, Properties:, and Applications: sections (I-3).
  4. Never reference internal EP-XXXX identifiers inside src/algebrax/ or docs/guide/.
  5. Registry Entry (src/algebrax/registry.py):
  6. Register a StructureEntry via _make_entry(...) with reified protocols= and laws= types (I-1, I-4).
  7. If the constructor requires arguments (zero_arg=False), provide a canonical example= factory (I-5).
  8. Verification Fixture (src/algebrax/verification/_registry_bridge.py):
  9. Add a StructureFixture and, if introducing a new protocol family, a verifier + negative Popper falsification test so python -m algebrax verify <Name> empirically tests every declared protocol and Law* witness (I-2).
  10. Add a traceability row in docs/verification.md referencing live *.py::test_* functions.
  11. Non-0-Cell Exports:
  12. 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_EXCLUSIONS in tests/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 by ruff).
  • 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 @property accessors.
  • Validate NaN, non-finite bounds, bool passed as int, and dimension/arity mismatches eagerly.
  • Escape all dynamic values in _repr_html_() via html.escape().
  • User Guide vs. Development Docs:
  • Keep docs/guide/ strictly user-facing — zero EP-XXXX IDs or roadmap phase labels.
  • Author architectural proposals under docs/proposals/EP-XXXX-*.md, register them in docs/eps.md, and validate frontmatter/structure before promotion to Final.

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:).

# Cut a release (updates pyproject.toml, CHANGELOG.md, and git tag)
cz bump --changelog