You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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).
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
+
5
27
## Development workflow
6
28
7
29
### Setting up
@@ -47,8 +69,12 @@ We also recommend setting up `ruff` to run automatically in your IDE.
47
69
48
70
If using `uv`, ruff is already included in the dev dependencies and can be run with:
49
71
```
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
52
78
```
53
79
54
80
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:
66
92
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.
67
93
2. Switch to the [`main`](https://github.com/talmolab/sleap-io/tree/main) branch and `git pull` to fetch the latest changes.
68
94
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.
73
116
74
117
75
118
## Tests and standards
@@ -81,7 +124,7 @@ See the [`.github/workflows`](.github/workflows) folder for how our checks are i
81
124
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/).
82
125
83
126
Our package configuration is defined in [`pyproject.toml`](pyproject.toml) which contains:
84
-
- Build system configuration
127
+
- Build system configuration (using setuptools)
85
128
- Package metadata and dependencies
86
129
- Optional dependencies (extras)
87
130
@@ -100,8 +143,8 @@ Best practices for adding dependencies include:
100
143
- 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).
101
144
102
145
For more reference see:
103
-
- [Configuring setuptools using `setup.cfg` files](https://setuptools.pypa.io/en/latest/userguide/declarative_config.html)
-[PEP 508 - Dependency specification for Python Software Packages](https://peps.python.org/pep-0508/)
106
149
107
150
**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.
118
161
119
162
Tests will be run on every commit across multiple operating systems and Python versions (see [`.github/workflows/ci.yml`](.github/workflows/ci.yml)).
120
163
164
+
#### Running tests locally
121
165
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/
124
169
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
126
172
127
-
### Live coverage
173
+
# Run a specific test function
174
+
uv run pytest tests/io/test_slp.py::test_load_slp -v
128
175
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/
130
178
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)
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.
140
192
141
193
142
194
### Code style
@@ -201,21 +253,40 @@ Valid examples:
201
253
0.1.10a2
202
254
```
203
255
204
-
### Build
256
+
### Build and Publishing
205
257
The PyPI-compatible package settings are in [`pyproject.toml`](pyproject.toml).
206
258
207
259
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.
208
260
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
211
266
uv build
267
+
268
+
# Build artifacts will be placed in dist/
269
+
ls dist/
212
270
```
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
216
283
```
217
284
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.
219
290
220
291
221
292
## Documentation website
@@ -227,3 +298,30 @@ To trigger an automated build (via the [`.github/workflows/build.yml`](.github/w
227
298
2. Build and tag a new version of the docs: `uv run mike deploy --update-aliases 0.1.4 latest`
228
299
3. Preview live changes locally with: `uv run mike serve`
229
300
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]`
0 commit comments