{"id":6414,"library":"pre-commit-uv","title":"pre-commit-uv","description":"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.","status":"active","version":"4.2.1","language":"en","source_language":"en","source_url":"https://github.com/tox-dev/pre-commit-uv","tags":["pre-commit","uv","developer-tools","productivity","git-hooks","python-packaging"],"install":[{"cmd":"pip install pre-commit-uv","lang":"bash","label":"Standard pip installation"},{"cmd":"pipx install pre-commit\npipx inject pre-commit pre-commit-uv","lang":"bash","label":"Recommended for global installation via pipx"},{"cmd":"uv tool install pre-commit --with pre-commit-uv --force-reinstall","lang":"bash","label":"Recommended for installing pre-commit with pre-commit-uv using uv"}],"dependencies":[{"reason":"pre-commit-uv is a plugin/patch for the pre-commit framework.","package":"pre-commit","optional":false},{"reason":"pre-commit-uv leverages uv for faster virtual environment and package management.","package":"uv","optional":false}],"imports":[],"quickstart":{"code":"# 1. Install uv (if you haven't already)\n# curl -LsSf https://astral.sh/uv/install.sh | sh\n\n# 2. Install pre-commit with pre-commit-uv using uv's tool installer\nuv tool install pre-commit --with pre-commit-uv\n\n# 3. Initialize git repository (if not already one)\ngit init\n\n# 4. Create a .pre-commit-config.yaml file in your project root\n#    (e.g., to use ruff for formatting and linting)\n# .pre-commit-config.yaml\n# ---\n# repos:\n#   - repo: https://github.com/astral-sh/ruff-pre-commit\n#     rev: v0.4.0 # Use 'pre-commit autoupdate' to keep this updated\n#     hooks:\n#       - id: ruff\n#         args: [--fix, --exit-non-zero-on-fix]\n#       - id: ruff-format\n\n# 5. Install the git hooks\npre-commit install\n\n# 6. (Optional) Run all hooks manually once\npre-commit run --all-files\n\n# Now, pre-commit will automatically use uv when running hooks.","lang":"bash","description":"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."},"warnings":[{"fix":"Set `DISABLE_PRE_COMMIT_UV_PATCH=1` or `FORCE_PRE_COMMIT_UV_PATCH=1` in your environment as needed.","message":"pre-commit-uv operates by patching `pre-commit` to use `uv`. If you encounter unexpected behavior or wish to temporarily disable this patching, you can set the `DISABLE_PRE_COMMIT_UV_PATCH` environment variable. Conversely, `FORCE_PRE_COMMIT_UV_PATCH` can be used to force patching if automatic detection fails.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider using supplementary tools like `sync-with-uv` (e.g., `github.com/tsvikas/sync-with-uv`) or `sync-pre-commit-with-uv` (e.g., `github.com/ewjoachim/sync-pre-commit-with-uv`) as an additional pre-commit hook to automatically update `rev` values based on your `uv.lock`.","message":"While `pre-commit-uv` significantly speeds up the *internal package management* for `pre-commit` hooks, it does not automatically synchronize the `rev` (version) fields for external hook repositories defined in your `.pre-commit-config.yaml` with your project's `pyproject.toml` or `uv.lock` file. This can lead to version drift where local tools and pre-commit hooks use different versions of the same dependency.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware that the very first execution of a new hook will involve setup time. Subsequent runs will leverage `uv`'s speed and `pre-commit`'s caching.","message":"Initial runs of any `pre-commit` hook (even with `pre-commit-uv`) may still take some time as `pre-commit` downloads and installs the necessary tools into isolated environments. `pre-commit-uv` primarily optimizes subsequent runs and the initial *seed* operation.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If using the `uv-lock` hook and desiring automatic staging, you might need to manually add `git add uv.lock` or configure a custom hook to stage the changes if `uv-lock` itself does not. Alternatively, review the hook's intended behavior.","message":"There are distinct tools related to `uv` and `pre-commit`. `pre-commit-uv` (this library) patches `pre-commit` to use `uv`. A separate project, `astral-sh/uv-pre-commit`, provides specific hooks (like `uv-lock`, `uv-export`) for `uv` itself. If you use the `uv-lock` hook from `astral-sh/uv-pre-commit`, be aware it might update your `uv.lock` file but not automatically add it to the Git index, leading to an unstaged change after the commit.","severity":"gotcha","affected_versions":"All versions (for `uv-lock` hook from `astral-sh/uv-pre-commit`)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z"}