Skip to content

tox-dev/pre-commit-uv

Repository files navigation

pre-commit-uv

PyPI PyPI - Implementation PyPI - Python Version Downloads PyPI - License check

Useuvto create virtual environments and install packages forpre-commit.

Installation

With pipx:

pipx install pre-commit
pipx inject pre-commit pre-commit-uv

With uv:

uv tool install pre-commit --with pre-commit-uv --force-reinstall

Why?

Compared to upstreampre-commitwill speed up the initial seed operation. In general, upstream recommends caching the pre-commitcache, however, that is not always possible and is still helpful to have a more performant initial cache creation., Here's an example of what you could expect demonstrated on this project's own pre-commit setup (with a hot uvcache):

❯ hyperfine'pre-commit install-hooks''pre-commit-uv install-hooks'
Benchmark 1: pre-commit install-hooks
Time (mean ± σ): 54.132 s ± 8.827 s [User: 15.424 s, System: 9.359 s]
Range (min… max): 45.972 s… 66.506 s 10 runs

Benchmark 2: pre-commit-uv install-hooks
Time (mean ± σ): 41.695 s ± 7.395 s [User: 7.614 s, System: 6.133 s]
Range (min… max): 32.198 s… 58.467 s 10 runs

Summary
pre-commit-uv install-hooks ran 1.30 ± 0.31timesfaster than pre-commit install-hooks

Configuration

Once installed will useuvout of box, however theDISABLE_PRE_COMMIT_UV_PATCHenvironment variable if is set it will work as an escape hatch to disable the new behavior.

To avoid interpreter startup overhead of the patching, we only perform this when we detect you callingpre-commit. Should this logic fail you can force the patching by setting theFORCE_PRE_COMMIT_UV_PATCHvariable. Should you experience this please raise an issue with the content of thesys.argv.Note thatDISABLE_PRE_COMMIT_UV_PATCHwill overwrite this flag should both be set.