|
| 1 | +--- |
| 2 | +description: Tooling, build system, and CI rules for python_nbdev_starter |
| 3 | +globs: "*" |
| 4 | +alwaysApply: true |
| 5 | +--- |
| 6 | + |
| 7 | +# Tooling Rules |
| 8 | + |
| 9 | +## Package Management |
| 10 | + |
| 11 | +- Always use `uv` for all package and environment operations. Never use `pip`, `pip install`, or bare `python` directly. |
| 12 | +- Install dependencies: `uv sync --all-extras` |
| 13 | +- Add a new dependency: `uv add <package>` |
| 14 | +- Run any command in the project venv: `uv run <command>` |
| 15 | +- Upgrade all deps: `uv sync --upgrade --all-extras --dev` |
| 16 | + |
| 17 | +## nbdev Commands |
| 18 | + |
| 19 | +- Export notebooks to Python: `uv run nbdev_export` |
| 20 | +- Test notebooks: `uv run nbdev_test` |
| 21 | +- Build docs: `uv run nbdev_docs` |
| 22 | +- Clean notebook outputs: `uv run nbdev_clean` |
| 23 | +- Always run `nbdev_export` after editing notebooks before running lint or tests. |
| 24 | + |
| 25 | +## Make Targets |
| 26 | + |
| 27 | +| Target | What it does | |
| 28 | +|---|---| |
| 29 | +| `make` (default) | Runs `agent-rules`, `install`, `lint`, `test` in order | |
| 30 | +| `make install` | `uv sync --all-extras` | |
| 31 | +| `make lint` | `uv run python devtools/lint.py` (codespell, ruff check --fix, ruff format, basedpyright) | |
| 32 | +| `make test` | `uv run pytest` | |
| 33 | +| `make nbdev-export` | Export notebooks to `python_nbdev_starter/` | |
| 34 | +| `make nbdev-test` | Run tests inside notebooks | |
| 35 | +| `make nbdev-docs` | Build documentation | |
| 36 | +| `make nbdev-clean` | Strip notebook outputs | |
| 37 | +| `make upgrade` | `uv sync --upgrade --all-extras --dev` | |
| 38 | +| `make build` | `nbdev_export` + `uv build` | |
| 39 | +| `make clean` | Removes dist, caches, .venv | |
| 40 | +| `make agent-rules` | Regenerates `CLAUDE.md` and `AGENTS.md` from `.cursor/rules/*.mdc` | |
| 41 | + |
| 42 | +## Testing |
| 43 | + |
| 44 | +- Test paths: `python_nbdev_starter`. Configured via `testpaths` in `pyproject.toml`. |
| 45 | +- `pythonpath = ["."]` is set in pytest config so imports resolve. |
| 46 | +- `python_files = ["*.py"]` — pytest discovers tests in any `.py` file. |
| 47 | +- Run all tests: `make test` |
| 48 | +- Run notebook tests: `make nbdev-test` |
| 49 | +- Run a single test with output: `uv run pytest -s path/to/file.py` |
| 50 | + |
| 51 | +## Linting |
| 52 | + |
| 53 | +- `make lint` runs `devtools/lint.py`, which executes in order: |
| 54 | + 1. `codespell --write-changes` on `python_nbdev_starter devtools README.md` |
| 55 | + 2. `ruff check --fix` on `python_nbdev_starter devtools` |
| 56 | + 3. `ruff format` on `python_nbdev_starter devtools` |
| 57 | + 4. `basedpyright --stats` on `python_nbdev_starter devtools` |
| 58 | +- Always run `make lint` after changes and fix all errors before considering work complete. |
| 59 | + |
| 60 | +## Versioning |
| 61 | + |
| 62 | +- Uses `uv-dynamic-versioning` which reads version from git tags at build time. |
| 63 | +- The `git` binary must be available for versioning to work. |
| 64 | +- `fetch-depth: 0` is required in CI checkout for full tag history. |
| 65 | +- Do not hardcode version strings; the version is always derived from git. |
| 66 | + |
| 67 | +## CI Pipeline |
| 68 | + |
| 69 | +- `test.yaml` uses `fastai/workflows/nbdev-ci@master` — the standard nbdev CI workflow. |
| 70 | +- Runs on push/PR/workflow_dispatch. |
| 71 | + |
| 72 | +## Post-Edit Validation Hook |
| 73 | + |
| 74 | +- `.claude/settings.json` registers a `PostToolUse` hook on `Edit|Write|NotebookEdit`. |
| 75 | +- The hook runs `.claude/validate.sh` with a 300-second timeout and `asyncRewake: true`. |
| 76 | +- Conditional logic in `validate.sh`: |
| 77 | + - **Skips entirely** for non-source files (`.md`, `.json`, `.yaml`, `.yml`, `.toml`, `.txt`, `.sh`, `.env`, `.gitignore`, `.dockerignore`). |
| 78 | + - **For `.ipynb` files**: runs `nbdev_export` first, then `make lint` and `make test`. |
| 79 | + - **For `.py` files**: always runs `make lint` and `make test`. |
| 80 | +- Exit code 2 on failure wakes the model to address the issue. |
| 81 | + |
| 82 | +## Pre-commit Hooks |
| 83 | + |
| 84 | +- To run hooks manually: `uv run pre-commit run --all-files` |
| 85 | +- Never skip pre-commit checks. If a hook fails, fix the underlying issue. |
0 commit comments