This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is an open-source book on building better code for science using AI, authored by Russell Poldrack. The rendered book is published at https://poldrack.github.io/BetterCodeBetterScience/.
# Install dependencies (uses uv package manager)
uv pip install -r pyproject.toml
uv pip install -e .
# Build book as HTML and serve locally
myst build --html
npx serve _build/html
# Build PDF (requires LaTeX)
jupyter-book build book/ --builder pdflatex
# Clean build artifacts
rm -rf book/_build# Run all tests
pytest
# Run tests with coverage
pytest --cov=src/bettercode --cov-report term-missing
# Run specific test modules
pytest tests/textmining/
pytest tests/property_based_testing/
pytest tests/narps/
# Run tests with specific markers
pytest -m unit
pytest -m integrationTest markers defined in pyproject.toml: unit and integration.
# Spell checking (configured in pyproject.toml)
codespell
# Python linting and formatting
ruff check .
ruff format .
# Pre-commit hooks (runs codespell)
pre-commit run --all-filesbook/- MyST markdown chapters (configured in myst.yml)src/bettercode/- Example Python code referenced in book chapterstests/- Test examples demonstrating testing concepts from the bookdata/- Data files for examplesscripts/- Utility scripts_build/- Build output (gitignored)
myst.yml- MyST book configuration (table of contents, exports, site settings)pyproject.toml- Python dependencies, pytest config, codespell settings.pre-commit-config.yaml- Pre-commit hooks (codespell)
- New text should be authored by a human (AI may be used to check/improve text)
- Code examples should follow PEP8
- Avoid introducing new dependencies when possible
- Custom words for codespell are in
project-words.txt
- Think about the problem before generating code.
- Write code that is clean and modular. Prefer shorter functions/methods over longer ones.
- Prefer reliance on widely used packages (such as numpy, pandas, and scikit-learn); avoid unknown packages from Github.
- Do not include any code in
__init__.pyfiles. - Use pytest for testing.
- Use functions rather than classes for tests. Use pytest fixtures to share resources between tests.
- Use numpy-style docstrings