|
| 1 | +# Contributing to DataJoint |
| 2 | + |
| 3 | +## Development Setup |
| 4 | + |
| 5 | +### Prerequisites |
| 6 | + |
| 7 | +- [Docker](https://docs.docker.com/get-docker/) (Docker daemon must be running) |
| 8 | +- [pixi](https://pixi.sh) (recommended) or Python 3.10+ |
| 9 | + |
| 10 | +### Quick Start with pixi |
| 11 | + |
| 12 | +[pixi](https://pixi.sh) manages all dependencies including Python, graphviz, and test tools: |
| 13 | + |
| 14 | +```bash |
| 15 | +git clone https://github.com/datajoint/datajoint-python.git |
| 16 | +cd datajoint-python |
| 17 | + |
| 18 | +# Run tests (containers managed automatically) |
| 19 | +pixi run test |
| 20 | + |
| 21 | +# Run with coverage |
| 22 | +pixi run test-cov |
| 23 | + |
| 24 | +# Run pre-commit hooks |
| 25 | +pixi run pre-commit run --all-files |
| 26 | +``` |
| 27 | + |
| 28 | +### Alternative: Using pip |
| 29 | + |
| 30 | +```bash |
| 31 | +pip install -e ".[test]" |
| 32 | +pytest tests/ |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## Running Tests |
| 38 | + |
| 39 | +Tests use [testcontainers](https://testcontainers.com/) to automatically manage MySQL and MinIO containers. No manual `docker-compose up` required. |
| 40 | + |
| 41 | +```bash |
| 42 | +pixi run test # All tests |
| 43 | +pixi run test-cov # With coverage |
| 44 | +pixi run -e test pytest tests/unit/ # Unit tests only |
| 45 | +pixi run -e test pytest tests/integration/test_blob.py -v # Specific file |
| 46 | +``` |
| 47 | + |
| 48 | +**macOS Docker Desktop users:** If tests fail to connect: |
| 49 | +```bash |
| 50 | +export DOCKER_HOST=unix://$HOME/.docker/run/docker.sock |
| 51 | +``` |
| 52 | + |
| 53 | +### External Containers (for debugging) |
| 54 | + |
| 55 | +```bash |
| 56 | +docker compose up -d db minio |
| 57 | +DJ_USE_EXTERNAL_CONTAINERS=1 pixi run test |
| 58 | +docker compose down |
| 59 | +``` |
| 60 | + |
| 61 | +### Full Docker |
| 62 | + |
| 63 | +```bash |
| 64 | +docker compose --profile test up djtest --build |
| 65 | +``` |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## Pre-commit Hooks |
| 70 | + |
| 71 | +Hooks run automatically on `git commit`. All must pass. |
| 72 | + |
| 73 | +```bash |
| 74 | +pixi run pre-commit install # First time only |
| 75 | +pixi run pre-commit run --all-files # Run manually |
| 76 | +``` |
| 77 | + |
| 78 | +Hooks include: **ruff** (lint/format), **codespell**, YAML/JSON/TOML validation. |
| 79 | + |
| 80 | +--- |
| 81 | + |
| 82 | +## Before Submitting a PR |
| 83 | + |
| 84 | +1. `pixi run test` — All tests pass |
| 85 | +2. `pixi run pre-commit run --all-files` — Hooks pass |
| 86 | +3. `pixi run test-cov` — Coverage maintained |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +## Environment Variables |
| 91 | + |
| 92 | +For `DJ_USE_EXTERNAL_CONTAINERS=1`: |
| 93 | + |
| 94 | +| Variable | Default | Description | |
| 95 | +|----------|---------|-------------| |
| 96 | +| `DJ_HOST` | `localhost` | MySQL hostname | |
| 97 | +| `DJ_PORT` | `3306` | MySQL port | |
| 98 | +| `DJ_USER` | `root` | MySQL username | |
| 99 | +| `DJ_PASS` | `password` | MySQL password | |
| 100 | +| `S3_ENDPOINT` | `localhost:9000` | MinIO endpoint | |
| 101 | + |
| 102 | +--- |
| 103 | + |
| 104 | +## Docstring Style |
| 105 | + |
| 106 | +Use **NumPy-style** docstrings for all public APIs: |
| 107 | + |
| 108 | +```python |
| 109 | +def insert(self, rows, *, replace=False): |
| 110 | + """ |
| 111 | + Insert rows into the table. |
| 112 | +
|
| 113 | + Parameters |
| 114 | + ---------- |
| 115 | + rows : iterable |
| 116 | + Rows to insert. Each row can be a dict, numpy record, or sequence. |
| 117 | + replace : bool, optional |
| 118 | + If True, replace existing rows with matching keys. Default is False. |
| 119 | +
|
| 120 | + Returns |
| 121 | + ------- |
| 122 | + None |
| 123 | +
|
| 124 | + Raises |
| 125 | + ------ |
| 126 | + DuplicateError |
| 127 | + When inserting a duplicate key without ``replace=True``. |
| 128 | +
|
| 129 | + Examples |
| 130 | + -------- |
| 131 | + >>> Mouse.insert1({"mouse_id": 1, "dob": "2024-01-15"}) |
| 132 | + """ |
| 133 | +``` |
| 134 | + |
| 135 | +### Section Order |
| 136 | + |
| 137 | +1. Short summary (one line, imperative mood) |
| 138 | +2. Extended description |
| 139 | +3. Parameters |
| 140 | +4. Returns / Yields |
| 141 | +5. Raises |
| 142 | +6. Examples (strongly encouraged) |
| 143 | +7. See Also |
| 144 | + |
| 145 | +### Style Rules |
| 146 | + |
| 147 | +- **Do:** Imperative mood ("Insert rows" not "Inserts rows") |
| 148 | +- **Do:** Include examples for public APIs |
| 149 | +- **Don't:** Document private methods extensively |
| 150 | +- **Don't:** Repeat function signature in description |
| 151 | + |
| 152 | +See [NumPy Docstring Guide](https://numpydoc.readthedocs.io/en/latest/format.html) for full reference. |
0 commit comments