Skip to content

Commit e029a81

Browse files
talmoclaude
andauthored
Documentation improvements for Claude Code and contributors (#215)
* Update CLAUDE.md with Claude Commands section - Document .claude/commands directory structure - Update linting commands to match lint.md - Add quick coverage command from coverage.md - Add PR description generation guidance - Reference command files for easier maintenance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Enhance CONTRIBUTING.md with practical developer guidance - Add Quick Start section for rapid onboarding with uv - Expand testing section with local test running examples - Include coverage checking commands and line-by-line annotation - Add code quality checks to PR workflow steps - Include comprehensive PR description guidelines - Add troubleshooting section for common issues - Document OpenCV import error workaround - Add commands for checking PR changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Update CONTRIBUTING.md packaging and publishing documentation - Remove live coverage section (using pytest-watch and VS Code extension) - Fix outdated setup.cfg reference - project uses pyproject.toml - Update PEP references to pyproject.toml standards (PEP 517/518) - Add comprehensive uv build and publish documentation - Include links to official uv package guide - Add TestPyPI publishing instructions - Expand build section to cover both manual and automated releases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * Simplify PyPI publishing docs to reflect Trusted Publisher setup - Remove PyPI token authentication instructions - Remove TestPyPI references (not used) - Add Trusted Publisher documentation link - Clarify that automated releases use GitHub Actions with Trusted Publisher - Keep minimal manual publishing command for rare cases 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d011f26 commit e029a81

5 files changed

Lines changed: 183 additions & 38 deletions

File tree

.claude/commands/coverage.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Run tests with coverage.
2+
3+
Command to run:
4+
```
5+
uv run pytest -q --maxfail=1 --cov --cov-branch && rm .coverage.* && uv run coverage annotate
6+
```
7+
8+
The result will be the terminal output and the line-by-line coverage will be in files sitting next to each module with the file naming `{module_name.py},cover`.
9+
10+
If you are working on a PR, figure out which files were changed and look for coverage specifically in those. If you don't know which files to look for coverage in, use this:
11+
12+
```
13+
git diff --name-only $(git merge-base origin/main HEAD) | jq -R . | jq -s .
14+
```

.claude/commands/lint.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Run linting with `ruff`.
2+
3+
Command:
4+
5+
```
6+
uv run ruff format sleap_io tests && uv run ruff check --fix sleap_io tests
7+
```
8+
9+
Then manually fix any remaining errors which cannot be automatically fixed by ruff.

.claude/commands/pr-description.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Update PR description.
2+
3+
Use the `gh` CLI to fetch the current PR description, then update it with a comprehensive description of the changes made in this PR.
4+
5+
If there is an associated issue (linked in the PR metadata or mentioned in the PR description), then use the `gh` CLI to fetch that too to contextualize the work done in the PR.
6+
7+
Include a summary, example usage (for enhancements), API changes, and other notes for future consideration (including reasoning behind design decisions).

CLAUDE.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ pip install -e .[dev,all]
4242

4343
### Linting
4444
```bash
45-
# Linting and format check (MUST pass before committing)
46-
uv run ruff check sleap_io tests
47-
uv run ruff format --check sleap_io tests
45+
# Auto-format and fix linting issues (from .claude/commands/lint.md)
46+
uv run ruff format sleap_io tests && uv run ruff check --fix sleap_io tests
4847

49-
# Auto-fix linting issues
50-
uv run ruff check --fix sleap_io tests
51-
uv run ruff format sleap_io tests
48+
# Check formatting without making changes
49+
uv run ruff format --check sleap_io tests
50+
uv run ruff check sleap_io tests
5251
```
5352

5453
### Testing
@@ -59,8 +58,11 @@ uv run pytest --cov=sleap_io --cov-report=xml tests/
5958
# Run specific test module
6059
uv run pytest tests/io/test_slp.py -v
6160

62-
# Check line-by-line coverage for a module
63-
uv run pytest tests/model/test_labels.py -v --cov=sleap_io --cov-report=json && uv run coverage annotate --include="*/sleap_io/model/labels.py"
61+
# Quick coverage check with line-by-line annotations (from .claude/commands/coverage.md)
62+
uv run pytest -q --maxfail=1 --cov --cov-branch && rm .coverage.* && uv run coverage annotate
63+
64+
# Check which files changed in PR for targeted coverage review
65+
git diff --name-only $(git merge-base origin/main HEAD) | jq -R . | jq -s .
6466

6567
# Watch mode for development
6668
uv run ptw
@@ -119,6 +121,21 @@ uv add --dev <package>
119121
uv sync --upgrade
120122
```
121123

124+
## Claude Commands
125+
126+
The `.claude/commands` directory contains useful command shortcuts for Claude Code:
127+
128+
- **lint.md**: Auto-format and fix linting issues with ruff
129+
- **coverage.md**: Run tests with coverage and generate line-by-line annotations
130+
- **pr-description.md**: Generate comprehensive PR descriptions using gh CLI
131+
132+
### PR Descriptions
133+
134+
When updating PR descriptions (from .claude/commands/pr-description.md):
135+
1. Fetch current PR metadata and linked issues using `gh` CLI
136+
2. Include: Summary, Key Changes, Example Usage, API Changes, Testing, and Design Decisions
137+
3. Document reasoning behind implementation choices for future reference
138+
122139
## Common Development Tasks
123140

124141
### Adding a New I/O Format

CONTRIBUTING.md

Lines changed: 128 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
This repository follows a set of standard development practices for modern Python packages.
44

5+
## Quick Start
6+
7+
For developers who want to get started quickly with [`uv`](https://docs.astral.sh/uv/):
8+
9+
```bash
10+
# Clone and setup
11+
git clone https://github.com/talmolab/sleap-io && cd sleap-io
12+
uv sync --all-extras
13+
14+
# Make changes on a new branch
15+
git checkout -b yourname/feature-name
16+
17+
# Before committing - format and lint
18+
uv run ruff format sleap_io tests && uv run ruff check --fix sleap_io tests
19+
20+
# Run tests
21+
uv run pytest tests/
22+
23+
# Check coverage
24+
uv run pytest -q --maxfail=1 --cov --cov-branch && rm .coverage.* && uv run coverage annotate
25+
```
26+
527
## Development workflow
628

729
### Setting up
@@ -47,8 +69,12 @@ We also recommend setting up `ruff` to run automatically in your IDE.
4769
4870
If using `uv`, ruff is already included in the dev dependencies and can be run with:
4971
```
50-
uv run ruff check
51-
uv run ruff format
72+
# Auto-format and fix linting issues
73+
uv run ruff format sleap_io tests && uv run ruff check --fix sleap_io tests
74+
75+
# Check without making changes
76+
uv run ruff format --check sleap_io tests
77+
uv run ruff check sleap_io tests
5278
```
5379
5480
Alternatively, you can install it globally with [`pipx`](https://pypa.github.io/pipx/):
@@ -66,10 +92,27 @@ Once you're set up, follow these steps to make a change:
6692
1. If you don't have push access to the repository, start by [making a fork](https://github.com/talmolab/sleap-io/fork) of the repository.
6793
2. Switch to the [`main`](https://github.com/talmolab/sleap-io/tree/main) branch and `git pull` to fetch the latest changes.
6894
3. Create a new branch named `<username>/<feature_name>` with a descriptive title for the change. For example: `talmo/nwb_support` or `talmo/update_dependencies`.
69-
4. Push as many commits as you want. Descriptive commit messages and titles are optional but recommended.
70-
5. Open a [Pull Request](https://github.com/talmolab/sleap-io/compare) of your new branch against `main` with a description of your changes. Feel free to create a "Draft" pull request to work on it incrementally.
71-
6. Once the [tests](#tests-and-standards) pass, request a review from a core developer and make any changes requested.
72-
7. Once approved, perform a [squash merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-pull-request-commits) against `main` to incorporate your changes.
95+
4. Make your changes and ensure code quality:
96+
```bash
97+
# Format and lint your code before committing
98+
uv run ruff format sleap_io tests && uv run ruff check --fix sleap_io tests
99+
100+
# Run tests to ensure nothing broke
101+
uv run pytest tests/
102+
103+
# Check test coverage for modified files
104+
uv run pytest --cov=sleap_io --cov-report=term
105+
```
106+
5. Push as many commits as you want. Descriptive commit messages and titles are optional but recommended.
107+
6. Open a [Pull Request](https://github.com/talmolab/sleap-io/compare) of your new branch against `main` with a description of your changes. Feel free to create a "Draft" pull request to work on it incrementally.
108+
7. Write a comprehensive PR description including:
109+
- Summary of changes
110+
- Example usage (for new features)
111+
- API changes (if any)
112+
- Testing approach
113+
- Design decisions and rationale
114+
8. Once the [tests](#tests-and-standards) pass, request a review from a core developer and make any changes requested.
115+
9. Once approved, perform a [squash merge](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/incorporating-changes-from-a-pull-request/about-pull-request-merges#squash-and-merge-your-pull-request-commits) against `main` to incorporate your changes.
73116

74117

75118
## Tests and standards
@@ -81,7 +124,7 @@ See the [`.github/workflows`](.github/workflows) folder for how our checks are i
81124
This package uses [`setuptools`](https://setuptools.pypa.io/en/latest/) as a [packaging and distribution system](https://packaging.python.org/en/latest/guides/distributing-packages-using-setuptools/).
82125

83126
Our package configuration is defined in [`pyproject.toml`](pyproject.toml) which contains:
84-
- Build system configuration
127+
- Build system configuration (using setuptools)
85128
- Package metadata and dependencies
86129
- Optional dependencies (extras)
87130

@@ -100,8 +143,8 @@ Best practices for adding dependencies include:
100143
- Don't pin to a single specific versions of dependencies unless absolutely necessary, and consider using [platform-specific specifiers](https://setuptools.pypa.io/en/latest/userguide/dependency_management.html#platform-specific-dependencies).
101144

102145
For more reference see:
103-
- [Configuring setuptools using `setup.cfg` files](https://setuptools.pypa.io/en/latest/userguide/declarative_config.html)
104-
- [Setuptools Keywords](https://setuptools.pypa.io/en/latest/references/keywords.html)
146+
- [PEP 517 - pyproject.toml-based builds](https://peps.python.org/pep-0517/)
147+
- [PEP 518 - Specifying build dependencies](https://peps.python.org/pep-0518/)
105148
- [PEP 508 - Dependency specification for Python Software Packages](https://peps.python.org/pep-0508/)
106149

107150
**Note:** We recommend using [`uv`](https://docs.astral.sh/uv/) for fast, reliable Python environment management. For backwards compatibility, a minimal conda environment is defined in [`environment.yml`](environment.yml) that simply installs the package via pip.
@@ -118,25 +161,34 @@ All tests must pass before a PR can be merged.
118161

119162
Tests will be run on every commit across multiple operating systems and Python versions (see [`.github/workflows/ci.yml`](.github/workflows/ci.yml)).
120163

164+
#### Running tests locally
121165

122-
### Coverage
123-
We check for coverage by parsing the outputs from `pytest` and uploading to [Codecov](https://app.codecov.io/gh/talmolab/sleap-io).
166+
```bash
167+
# Run full test suite
168+
uv run pytest tests/
124169

125-
All changes should aim to increase or maintain test coverage.
170+
# Run a specific test module
171+
uv run pytest tests/io/test_slp.py -v
126172

127-
### Live coverage
173+
# Run a specific test function
174+
uv run pytest tests/io/test_slp.py::test_load_slp -v
128175

129-
*The following steps are based on [this guide](https://jasonstitt.com/perfect-python-live-test-coverage).*
176+
# Run with coverage report
177+
uv run pytest --cov=sleap_io --cov-report=term tests/
130178

131-
1. If you already have an environment installed, ensure you have the latest dev tools (namely `pytest-watch`):
132-
- With `uv`: `uv sync --all-extras`
133-
- With pip: `pip install -e ."[dev]"`
134-
2. Install the [Coverage Gutters extension](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) in VS Code.
135-
3. Open a terminal and run the test watcher:
136-
- With `uv`: `uv run ptw`
137-
- With conda: `conda activate sleap-io && ptw`
138-
This will generate a new `lcov.info` file when it's done.
139-
4. Enable the coverage gutters by using **Ctrl/Cmd**+**Shift**+**P**, then **Coverage Gutters: Display Coverage**.
179+
# Quick coverage check with line-by-line annotations
180+
uv run pytest -q --maxfail=1 --cov --cov-branch && rm .coverage.* && uv run coverage annotate
181+
# This creates .py,cover files next to each module showing line-by-line coverage
182+
183+
# Check which files changed in your PR (useful for targeted testing)
184+
git diff --name-only $(git merge-base origin/main HEAD)
185+
```
186+
187+
188+
### Coverage
189+
We check for coverage by parsing the outputs from `pytest` and uploading to [Codecov](https://app.codecov.io/gh/talmolab/sleap-io).
190+
191+
All changes should aim to increase or maintain test coverage.
140192

141193

142194
### Code style
@@ -201,21 +253,40 @@ Valid examples:
201253
0.1.10a2
202254
```
203255

204-
### Build
256+
### Build and Publishing
205257
The PyPI-compatible package settings are in [`pyproject.toml`](pyproject.toml).
206258

207259
The version number is set in [`sleap_io/version.py`](sleap_io/version.py) in the `__version__` variable. This is read automatically by setuptools during installation and build.
208260

209-
To manually build (e.g., locally):
210-
```
261+
#### Building with uv
262+
263+
To build the package locally:
264+
```bash
265+
# Build source distribution and wheel
211266
uv build
267+
268+
# Build artifacts will be placed in dist/
269+
ls dist/
212270
```
213-
Or with Python's build module:
214-
```
215-
python -m build --wheel
271+
272+
For more details, see the [uv guide on building packages](https://docs.astral.sh/uv/guides/package/).
273+
274+
#### Publishing to PyPI
275+
276+
Publishing to PyPI is handled automatically via GitHub Actions using [Trusted Publisher](https://docs.pypi.org/trusted-publishers/). This means no tokens or passwords are needed for releases from GitHub.
277+
278+
For manual/local publishing with `uv` (rarely needed):
279+
```bash
280+
# Build and publish
281+
uv build
282+
uv publish
216283
```
217284

218-
To trigger an automated build (via the [`.github/workflows/build.yml`](.github/workflows/build.yml) action), [publish a Release](https://github.com/talmolab/sleap-io/releases/new).
285+
See the [uv publishing documentation](https://docs.astral.sh/uv/guides/package/#publishing-packages) for more details.
286+
287+
#### Automated releases
288+
289+
To trigger an automated build and release (via the [`.github/workflows/build.yml`](.github/workflows/build.yml) action), [publish a Release](https://github.com/talmolab/sleap-io/releases/new). The GitHub Action will automatically authenticate with PyPI using Trusted Publisher and upload the built packages.
219290

220291

221292
## Documentation website
@@ -227,3 +298,30 @@ To trigger an automated build (via the [`.github/workflows/build.yml`](.github/w
227298
2. Build and tag a new version of the docs: `uv run mike deploy --update-aliases 0.1.4 latest`
228299
3. Preview live changes locally with: `uv run mike serve`
229300
4. Manually push a specific version with: `uv run mike deploy --push --update-aliases --allow-empty 0.1.4 latest`
301+
302+
## Troubleshooting
303+
304+
### Common Issues
305+
306+
#### OpenCV import errors during testing
307+
If you encounter cv2/OpenCV import errors when running individual tests:
308+
- Try running the entire test module instead: `uv run pytest tests/io/test_video.py`
309+
- Or run the full test suite: `uv run pytest tests/`
310+
- This is a known OpenCV issue with importing submodules
311+
312+
#### Video backend dependencies
313+
sleap-io has optional video backend dependencies:
314+
- Install all backends: `uv sync --all-extras` or `pip install -e .[all]`
315+
- Install OpenCV only: `pip install -e .[opencv]`
316+
- Install PyAV only: `pip install -e .[av]`
317+
318+
#### Environment issues
319+
If you're having environment problems:
320+
- With `uv`: `uv sync --all-extras --refresh`
321+
- With conda: `conda env remove -n sleap-io && conda env create -f environment.yml`
322+
323+
#### Finding what changed in your PR
324+
To see which files you've modified (useful for targeted testing):
325+
```bash
326+
git diff --name-only $(git merge-base origin/main HEAD)
327+
```

0 commit comments

Comments
 (0)