Contributing
This guide covers the development setup, conventions, and workflow for
contributing to meridian-tools.
Development setup
Clone and install
The [dev] extra installs pytest, ruff, and mypy.
Verify the install
Acceptance gate
Before submitting any change, run the full acceptance sequence from the repository root:
See acceptance.md for the expected results and how to interpret failures.
Code style
Formatting and linting
The project uses Ruff for both linting and formatting:
Configuration is in pyproject.toml:
Type annotations
All public functions and classes use type annotations. The codebase uses
from __future__ import annotations for forward-reference support.
Import conventions
- Standard library imports first, then third-party, then local.
- Heavy dependencies (Meridian, TensorFlow, ArviZ) are imported lazily inside functions, not at module level, in the config/CLI/validation layers.
- Ruff rule
Ienforces import sorting.
Configuration models
All Pydantic models use ConfigDict(extra="forbid"). New config fields must
be added with appropriate types, defaults, and validators.
Testing
Running tests
Test conventions
- Tests use
pytestwithtmp_pathfor temporary directories. monkeypatchis used extensively to mock Meridian internals and isolate unit tests from real MCMC sampling.- Module-scoped fixtures (
scope="module") are used for expensive model construction intest_log_likelihood.pyandtest_model_selection.py. - Shared test infrastructure is defined inline in individual test modules.
There is no top-level
conftest.py.
Live Meridian verification
One opt-in command exercises the bounded real Meridian seam:
This is not part of the default suite. It proves one reduced real pipeline run over bundled demo data, one stored-run refresh after the original YAML is removed, and the lower-level live log-likelihood seam. Run it after Meridian version upgrades and before release-candidate handoff when you want extra confidence beyond the fast suite.
Writing new tests
- Place tests in the appropriate
tests/test_<module>.pyfile. - Use
monkeypatchto avoid real MCMC sampling in unit tests. - Test both success paths and error conditions.
- Verify artefact file contents, not just their existence.
- Use
tmp_pathfor all filesystem operations.
Project structure
Versioning
The version is defined in src/meridian_tools/version.py:
Version bumps are manual edits. Update this file when preparing a release.
Documentation
Documentation lives in docs/. When adding new features:
- Update relevant guide or reference pages.
- Add API documentation for new public functions or classes.
- Update the YAML schema reference if config fields changed.
- Update the output schema if new artefacts are produced.
Common pitfalls
- Do not import Meridian at module level in config, CLI, or validation modules. This breaks CLI responsiveness.
- Do not add
extra="allow"to Pydantic models. Theextra="forbid"policy prevents silent misconfiguration. - Do not modify source run directories in lifecycle operations. Always create new sibling directories.
- Do not weaken or delete existing tests without explicit direction.