|
| 1 | +# Contributing |
| 2 | + |
| 3 | +A guide to contributing code to any of the Tools for Experiments repositories. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Workflow overview |
| 8 | + |
| 9 | +### 1. Fork the repository |
| 10 | + |
| 11 | +Go to the GitHub page of the repository you want to contribute to and click **Fork** in the top-right corner. This creates a personal copy of the repo under your GitHub account. |
| 12 | + |
| 13 | +### 2. Clone your fork locally |
| 14 | + |
| 15 | +```bash |
| 16 | +git clone https://github.com/<your-username>/<repo-name>.git |
| 17 | +cd <repo-name> |
| 18 | +``` |
| 19 | + |
| 20 | +### 3. Create a new branch |
| 21 | + |
| 22 | +Never commit directly to `main`. Create a dedicated branch for your changes: |
| 23 | + |
| 24 | +```bash |
| 25 | +git checkout -b my-feature-branch |
| 26 | +``` |
| 27 | + |
| 28 | +Use a short, descriptive name (e.g. `fix-calibration-bug`, `add-sweep-tool`). |
| 29 | + |
| 30 | +### 4. Make your changes |
| 31 | + |
| 32 | +Edit the code, add new files, or fix bugs. Once you're happy with the changes, stage and commit them: |
| 33 | + |
| 34 | +```bash |
| 35 | +git add <files> |
| 36 | +git commit -m "Short description of what you changed" |
| 37 | +``` |
| 38 | + |
| 39 | +### 5. Set up the environment with uv |
| 40 | + |
| 41 | +Each repository uses uv to manage its environment. From the root of the cloned repo, run: |
| 42 | + |
| 43 | +```bash |
| 44 | +uv sync |
| 45 | +``` |
| 46 | + |
| 47 | +This installs all dependencies (including dev tools like `ruff`, `mypy`, and `pytest`) into a local `.venv`. You don't need to activate it — prefix every command with `uv run` and uv will use the right environment automatically. |
| 48 | + |
| 49 | +### 6. Run the checks locally |
| 50 | + |
| 51 | +Before pushing, run the three checks below to catch issues early. **The CI pipeline runs the same checks automatically and will block your pull request from merging if any of them fail.** |
| 52 | + |
| 53 | +Run all commands from the root of the repository (where `pyproject.toml` lives). |
| 54 | + |
| 55 | +#### Linting — ruff |
| 56 | + |
| 57 | +[ruff](https://docs.astral.sh/ruff/) checks code style and common errors: |
| 58 | + |
| 59 | +```bash |
| 60 | +uv run ruff check |
| 61 | +``` |
| 62 | + |
| 63 | +The `.` (current directory) is implied when no path is given, so running `uv run ruff check` from the repo root checks all files in the project. To auto-fix issues where possible: |
| 64 | + |
| 65 | +```bash |
| 66 | +uv run ruff check --fix |
| 67 | +``` |
| 68 | + |
| 69 | +#### Type checking — mypy |
| 70 | + |
| 71 | +[mypy](https://mypy.readthedocs.io/) checks for type errors: |
| 72 | + |
| 73 | +```bash |
| 74 | +uv run mypy |
| 75 | +``` |
| 76 | + |
| 77 | +Again, run this from the repo root — mypy reads the project configuration from `pyproject.toml` and knows which files to check. |
| 78 | + |
| 79 | +Fix any reported type errors before submitting. |
| 80 | + |
| 81 | +#### Tests — pytest |
| 82 | + |
| 83 | +[pytest](https://docs.pytest.org/) runs the test suite: |
| 84 | + |
| 85 | +```bash |
| 86 | +uv run pytest |
| 87 | +``` |
| 88 | + |
| 89 | +All tests must pass. If you added new functionality, add tests for it too. |
| 90 | + |
| 91 | +### 7. Push and open a pull request |
| 92 | + |
| 93 | +```bash |
| 94 | +git push origin my-feature-branch |
| 95 | +``` |
| 96 | + |
| 97 | +Then go to your fork on GitHub and click **Compare & pull request**. Fill in a description of what your changes do and why, then submit. |
| 98 | + |
| 99 | +The CI pipeline will run `ruff`, `mypy`, and `pytest` automatically. You can follow the results in the **Checks** tab of your pull request. All checks must pass before the PR can be merged. |
| 100 | + |
| 101 | +--- |
| 102 | + |
| 103 | +## Contributing to the documentation |
| 104 | + |
| 105 | +The docs are written in Markdown using [MyST](https://myst-parser.readthedocs.io/) and built with [Sphinx](https://www.sphinx-doc.org/). Every page is a `.md` file inside the `docs/` directory. |
| 106 | + |
| 107 | +### How the docs are organized |
| 108 | + |
| 109 | +``` |
| 110 | +docs/ |
| 111 | +├── conf.py # Sphinx configuration |
| 112 | +├── index.md # Top-level table of contents |
| 113 | +├── guides/ |
| 114 | +│ ├── index.md # Section table of contents |
| 115 | +│ └── *.md # Individual guide pages |
| 116 | +├── contributing/ |
| 117 | +│ └── *.md |
| 118 | +└── examples/ |
| 119 | + └── *.md |
| 120 | +``` |
| 121 | + |
| 122 | +Each `index.md` contains a `{toctree}` directive that lists the pages in that section. When you add a new page, register it there. |
| 123 | + |
| 124 | +### Adding a new page |
| 125 | + |
| 126 | +1. Create a new `.md` file in the appropriate section folder. |
| 127 | +2. Add its filename (without extension) to the `{toctree}` in that folder's `index.md`: |
| 128 | + |
| 129 | + ````markdown |
| 130 | + ```{toctree} |
| 131 | + :maxdepth: 2 |
| 132 | +
|
| 133 | + existing-page |
| 134 | + your-new-page |
| 135 | + ``` |
| 136 | + ```` |
| 137 | + |
| 138 | +### Editing an existing page |
| 139 | + |
| 140 | +Just edit the `.md` file directly — it is plain Markdown with optional MyST directives. |
| 141 | + |
| 142 | +### Building the docs locally |
| 143 | + |
| 144 | +The docs repo has its own `pyproject.toml` at the root of `toolsforexperiments/` that includes Sphinx and its dependencies. First sync the environment: |
| 145 | + |
| 146 | +```bash |
| 147 | +uv sync |
| 148 | +``` |
| 149 | + |
| 150 | +Then build the HTML from the `docs/` directory: |
| 151 | + |
| 152 | +```bash |
| 153 | +cd docs |
| 154 | +uv run make html |
| 155 | +``` |
| 156 | + |
| 157 | +The output is written to `docs/build/html/`. Open `docs/build/html/index.html` in your browser to preview the result: |
| 158 | + |
| 159 | +```bash |
| 160 | +open docs/build/html/index.html # macOS |
| 161 | +xdg-open docs/build/html/index.html # Linux |
| 162 | +``` |
| 163 | + |
| 164 | +To do a clean rebuild from scratch (useful if pages aren't updating): |
| 165 | + |
| 166 | +```bash |
| 167 | +cd docs |
| 168 | +uv run make clean html |
| 169 | +``` |
0 commit comments