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]pre-commit installThis will automatically format your code and check for issues before each commit.
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)
- Trailing whitespace removal (Python, Fortran, Jupyter notebooks)
- End-of-file fixing (Python, Fortran, Jupyter notebooks)
- PyUpgrade for Python 3.10+ syntax
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 only ruff formatting
ruff format camb fortran/tests
# Run only ruff linting with fixes
ruff check --fix camb fortran/testsRun the test suite to ensure your changes don't break anything:
python -m unittest camb.tests.camb_testFor 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 findent
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
For enhanced Fortran development, you may want to install:
pip install findent 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)"