Reproducible Python project contract
First classify the repository:
| Project | Build system | Installation expectation |
|---|---|---|
| Application/non-package | Usually none; optionally tool.uv.package = false |
Sync dependencies, do not invent a distributable package. |
| Library/package | Explicit [build-system] and package layout |
Build and inspect wheel plus sdist. |
| Workspace | Root membership plus member metadata | One shared lock; run member-specific commands deliberately. |
Workflow
- Inspect existing
pyproject.toml,uv.lock, Python constraint, source layout, build backend, dependency groups/extras, tool configuration, CI, and current commands before changing anything. - Preserve the declared project type. Do not add a build system merely to make an application look like a package.
- Put runtime dependencies in
[project.dependencies], optional consumer features in[project.optional-dependencies], and development tools in[dependency-groups]. Keep environment markers explicit. - Use
uv add/removeor an intentional metadata edit followed byuv lock. Commituv.lockfor reproducible projects; never edit it manually. - Use
uv syncfor an exact project environment anduv runfor commands. In CI or verification, use--lockedso stale metadata fails rather than silently updating the lock. - Configure one canonical quality pipeline: Ruff check and format, Pyright, pytest, and build inspection when the project is distributable.
- For a package, run
uv build, inspect sdist/wheel contents and metadata, install the wheel into a clean environment, then import and exercise its public entry point.
Invariants
pyproject.tomldeclares intent;uv.lockrecords resolution;.venvis generated state and is not committed.- A passing editable install is not proof that the built wheel contains the package or data files.
- Extras are consumer-selectable features; dependency groups are development or task environments. Do not use one as the other.
- Never invoke publishing or handle registry tokens without explicit authority.
- Preview uv features and tool schemas are version-sensitive; inspect installed help and current official docs before encoding them.
uv lock --check
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked pyright
uv run --locked pytest
uv build
Use project and dependency layout, quality and build verification, and migration safeguards.