pre-commit-uv

4.2.1 · active · verified Wed Apr 15

pre-commit-uv is a Python library that patches the `pre-commit` framework to use `uv` for creating virtual environments and installing packages for its hooks. This integration significantly speeds up the initial setup and caching operations of `pre-commit` hooks. Currently at version 4.2.1, the library is actively maintained with regular updates.

Warnings

Install

Quickstart

To get started, install `pre-commit` using `uv`'s tool installer, ensuring `pre-commit-uv` is included as a plugin. Once installed, configure your `.pre-commit-config.yaml` with your desired hooks. `pre-commit-uv` automatically patches `pre-commit` to use `uv` for managing the hook environments, improving performance without changes to your hook configurations.

# 1. Install uv (if you haven't already)
# curl -LsSf https://astral.sh/uv/install.sh | sh

# 2. Install pre-commit with pre-commit-uv using uv's tool installer
uv tool install pre-commit --with pre-commit-uv

# 3. Initialize git repository (if not already one)
git init

# 4. Create a .pre-commit-config.yaml file in your project root
#    (e.g., to use ruff for formatting and linting)
# .pre-commit-config.yaml
# ---
# repos:
#   - repo: https://github.com/astral-sh/ruff-pre-commit
#     rev: v0.4.0 # Use 'pre-commit autoupdate' to keep this updated
#     hooks:
#       - id: ruff
#         args: [--fix, --exit-non-zero-on-fix]
#       - id: ruff-format

# 5. Install the git hooks
pre-commit install

# 6. (Optional) Run all hooks manually once
pre-commit run --all-files

# Now, pre-commit will automatically use uv when running hooks.

view raw JSON →