Thank you for your interest in contributing to CAMB! This guide will help you set up your development environment and understand our code standards.
git clone --recursive https://github.com/cmbant/CAMB.git
cd CAMB
pip install -e .[dev]git config core.hooksPath .githooksThe repository ships a portable .githooks/pre-commit wrapper that looks for pre-commit in the CAMB devcontainer
environment first, then in the current checkout's .venv, then in the main checkout's .venv when you are committing
from a linked worktree, then on your PATH. This keeps the same checkout working on a Linux devcontainer and a Windows
host without rewriting the hook each time you switch environments.
CAMB uses Ruff for Python formatting and linting:
- Line length: 120 characters
- Quote style: Double quotes
- Python version: 3.10+
- Import sorting: Automatic via ruff
- Target version: py310
The pre-commit hooks include:
- Ruff formatting and linting (Python files)
forformatfor Fortran formatting, using the[tool.forformat]settings inpyproject.toml- Trailing whitespace removal (Python, Fortran, Jupyter notebooks)
- End-of-file fixing (Python, Fortran, Jupyter notebooks)
- PyUpgrade for Python 3.10+ syntax
The Fortran hook comes from the forformat-pre-commit hook
repository, installs the published forformat wheel, operates on the Fortran
files selected by pre-commit, and excludes the forutils submodule. forformat uses the surrounding Git checkout to
resolve declarations while modifying only the selected files.
The pre-commit hooks will run automatically, but you can also run them manually:
# Run all pre-commit hooks
pre-commit run --all-files
# Run the Fortran hooks on selected files
pre-commit run forformat fortran/path.f90
# Run only ruff formatting
pre-commit run ruff-format --files camb fortran/tests
# Run only ruff linting with fixes
pre-commit run ruff-check --files camb fortran/testsRun the test suite to ensure your changes don't break anything:
python -m unittest camb.tests.camb_testTo run the full suite including the slower symbolic and emission-angle tests:
python -m unittest camb.tests.camb_test camb.tests.camb_test_slowThe GitHub workflows include camb.tests.camb_test_slow by default, and skip it when CAMB_TEST_FAST is set.
For HMcode tests (Linux only):
git clone https://github.com/alexander-mead/HMcode_test_outputs.git
python -m unittest camb.tests.hmcode_testThe repository includes VS Code configuration files with:
- Recommended extensions: Python, Ruff, Fortran linter
- Format on save: Enabled with Ruff as the default Python formatter
- Rulers at 120 characters
- Pylance settings: Configured to silence most NumPy-related type errors
- Fortran formatting: Configured with forformat in
pyproject.toml; the same settings are used by theforformatpre-commit hook - Fortran project context: The Modern Fortran adapter passes the workspace folder to forformat so it can find the
checkout and its
pyproject.toml
The following extensions will be suggested when you open the project:
ms-python.python- Python supportms-python.debugpy- Python debuggingcharliermarsh.ruff- Ruff formatter and linterfortran-lang.linter-gfortran- Fortran support
The committed workspace settings only help VS Code discover a local ./.venv; the devcontainer sets its
container-local interpreter separately, so host and container environments do not fight each other.
For enhanced Fortran development, you may want to install:
pip install forformat fortlsNote: You may need to configure global VS Code settings for Fortran tool paths.
- Install pre-commit hooks before making changes
- Test your changes locally
- Write clear commit messages
- Keep PRs focused on a single feature or fix
- Update documentation if needed
- Ensure CI passes - GitHub Actions will check formatting and run tests
- Check the documentation
- Ask on CosmoCoffee
- Open an issue for bugs or feature requests
If you're an AI agent contributing code, follow these guidelines:
- Use author name "AI agent" when creating PRs
- Include clear commit messages indicating AI authorship:
git commit -m "Fix issue XYZ (AI agent)"