1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88# [Using uv in pre-commit](#using-uv-in-pre-commit)
An official pre-commit hook is provided at [`astral-sh/uv-pre-commit`](https://github.com/astral-sh/uv-pre-commit).
To use uv with pre-commit, add one of the following examples to the `repos` list in the `.pre-commit-config.yaml`.
To make sure your `uv.lock` file is up to date even if your `pyproject.toml` file was changed:
.pre-commit-config.yaml
```
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.26
hooks:
- id: uv-lock
```
To keep a `requirements.txt` file in sync with your `uv.lock` file:
.pre-commit-config.yaml
```
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.26
hooks:
- id: uv-export
```
To compile requirements files:
.pre-commit-config.yaml
```
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.26
hooks:
# Compile requirements
- id: pip-compile
args: [requirements.in, -o, requirements.txt]
```
To compile alternative requirements files, modify `args` and `files`:
.pre-commit-config.yaml
```
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.26
hooks:
# Compile requirements
- id: pip-compile
args: [requirements-dev.in, -o, requirements-dev.txt]
files: ^requirements-dev\.(in|txt)$
```
To run the hook over multiple files at the same time, add additional entries:
.pre-commit-config.yaml
```
repos:
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.9.26
hooks:
# Compile requirements
- id: pip-compile
name: pip-compile requirements.in
args: [requirements.in, -o, requirements.txt]
- id: pip-compile
name: pip-compile requirements-dev.in
args: [requirements-dev.in, -o, requirements-dev.txt]
files: ^requirements-dev\.(in|txt)$
```