Python UV Rules Reference¶
Base Policy¶
- Use
uvby default for Python projects. - Write tests for behavior-impacting changes.
- Run scripts with
uv run <script>.
Project setup when requested¶
Install hooks only when the project or repository requires them:
Example .pre-commit-config.yaml template¶
Use this template for a new project or an explicit hook-configuration request. Do not create this file for an isolated script edit.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/jendrikseipp/vulture
hooks:
- id: vulture
- repo: local
hooks:
- id: ruff
name: ruff (uv)
entry: uv run ruff check --fix --exit-non-zero-on-fix
language: system
types_or: [python, pyi]
- id: ruff-format
name: ruff format (uv)
entry: uv run ruff format
language: system
types_or: [python, pyi]
- id: pytest
name: pytest (uv)
entry: uv run pytest -vsx
language: system
pass_filenames: false
Example Makefile target¶
Add this target only when the project or repository asks for a Makefile-based setup command.
Exploratory Debugging¶
Refactoring from Original Implementation¶
- Move workflow to
uvif not already using it. - Add original dependencies as needed:
uv add --optional original-impl <module>. - Add tests if missing and use the project's coverage tool when its policy requires one.
- Match the repository's coverage target; do not impose a universal percentage.
- Prefer small real datasets described in project docs.
- Compare original and refactored outputs for parity.