Contributing¶
Contributions to spectracles are welcome, whether a bug report, a fix, a new model component or a clearer page in these docs. This page describes how to set up a copy to work on and what a pull request needs.
Setting up¶
spectracles uses uv to manage its environment. Clone the repository and install it with its development dependencies:
uv sync builds jax-finufft from source, from its git repository, so you need FFTW installed first (for example brew install fftw on macOS, or libfftw3-dev on Debian and Ubuntu). The development dependencies include NIFTy.re, BlackJAX and astropy, so the whole test suite can run.
Run any command in the environment with uv run, e.g. uv run python my_script.py.
Running the tests¶
runs everything. To run one file, one class or one test:
uv run pytest tests/test_spatial.py
uv run pytest tests/test_spatial.py::TestFourierGP
uv run pytest tests/test_spatial.py::TestFourierGP::test_realised_covariance
Add -x to stop at the first failure, or -k word to run only tests whose names contain word. Tests run in float64. New functionality should come with tests.
Linting and formatting¶
The code is linted and formatted with Ruff, with a line length of 99:
uv run ruff check --fix . fixes what it safely can. CI runs ruff check . and ruff format --check ., so run both before pushing.
Type checking¶
The package is checked with pyright, which isn't in the development dependencies; install it however you like (for example pipx install pyright). Then
should report no errors. pyproject.toml points pyright at the project's .venv and excludes spectracles.lvm_models, which is experimental and not type-checked.
Documentation¶
The documentation is Markdown in docs/, built with MkDocs Material, and the API reference is generated from docstrings by mkdocstrings. Preview it with live reload:
and open the address it prints. To check that it builds without warnings, as CI does:
New pages go in the nav section of mkdocs.yml. CI builds the docs on every pull request and deploys them when a version is tagged.
Code on the docs pages is tested¶
tests/test_docs.py runs the ```python blocks of the guide and example pages, in order, as one script per page, so the examples can't go stale. Pages are listed in its PAGES dict with any optional packages they need. If you add a guide page with code, add it there too.
- A block whose first line is
# sketchis illustrative only and is skipped. - A line like
n_draws = 600 # fast in tests: 20runs with the faster value in the tests, while readers see the real one.
Run just these tests with uv run pytest tests/test_docs.py.
Docstrings¶
Docstrings use Google style (Args:, Returns:, Raises: sections), which the API reference renders. Describe what the code does and how to use it. Leave out its history (what it used to do, why it changed, how it was tested): that belongs in commit messages and the changelog.
Pull requests¶
- Create a branch from
main(on a fork, if you don't have write access). - Make your changes, with tests and docs as needed.
- Add an entry to the changelog under Unreleased, in the right group (Added, Changed, Deprecated, Removed or Fixed). Say plainly if the change affects results or breaks existing code.
- Open a pull request against
main.
CI must pass: the lint job (ruff check and ruff format --check), the tests on Python 3.11, 3.12, 3.13 and 3.14, and the strict docs build.
Reporting issues¶
Report bugs and request features through GitHub Issues. For a bug, include your Python, JAX and spectracles versions, a small example that shows the problem, and the full error message.