Skip to content

Building and testing

Run these from the rust folder.

Build

cargo build --release                  # library and pk (target/release/pk)
cargo clippy --release                 # lints

cargo build and cargo test cover phytkit-core and phytkit-cli only. The Python crate is a Python extension and can only be linked by maturin:

VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop --release -m crates/py/Cargo.toml

Test

cargo test --release                   # unit tests and model reference values
.venv/bin/python -m pytest crates/py/tests

The Python tests compare phytkit.run with the pk binary on the example data, so build pk first.

The model tests check every model's predictions, derivatives and fits against values stored in crates/core/tests/data/model_reference.json. After changing a model on purpose, rewrite the stored values from the current code and review the difference:

UPDATE_MODEL_REFERENCE=1 cargo test --release --test model_reference
git diff --stat crates/core/tests/data/model_reference.json

Example data

examples/ holds synthetic example files, used by the tests and these docs. They're generated by a seeded script, so they can be reproduced exactly:

python3 examples/make_examples.py

Documentation

python3 -m venv .docs-venv && .docs-venv/bin/pip install -r docs/requirements.txt
python3 docs/gen_models.py                       # regenerate the model reference from pk describe
cd docs && ../.docs-venv/bin/mkdocs serve        # preview at http://127.0.0.1:8000
cd docs && ../.docs-venv/bin/mkdocs build --strict

docs/check_examples.sh runs every pk command in the docs that uses the sample data, and fails if any of them errors.

Continuous integration and releases

GitHub Actions runs three workflows from .github/workflows/:

  • ci.yml, on every push to main and every pull request: cargo fmt --check, clippy (warnings are errors), cargo test --release on Linux, macOS and Windows, a cargo check on Rust 1.88, the Python tests against a freshly built wheel on Python 3.9 to 3.13, and the docs checks (docs/check_examples.sh, an up-to-date reference/models.md, and mkdocs build --strict).
  • docs.yml, on pushes to main that change docs/: builds this site and publishes it to GitHub Pages.
  • release.yml, on a v* tag: builds abi3 wheels (Linux x86_64 and aarch64, macOS arm64 and x86_64, Windows x86_64) and an sdist, installs and tests each wheel on Python 3.9 and 3.13, publishes to PyPI with Trusted Publishing, and creates a GitHub release. Run it by hand from the Actions tab for a dry run that builds and tests without publishing.

To release, bump workspace.package.version in the root Cargo.toml (the Python package takes its version from there), commit, and push a matching tag:

git tag v0.2.0
git push origin v0.2.0

The workflow stops before building if the tag and the Cargo version differ.