mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 20:31:12 +00:00
## Summary
rooster should pick those up, but those 2 references were added to 0.5.8
while a 0.5.9 was already released
(f5add0ca5e),
so they never got bumped automatically.
I've searched for other cases like this in the documentation on other
versions, just in case, and it seems that this is the only case.
74 lines
2 KiB
Markdown
74 lines
2 KiB
Markdown
---
|
|
title: Using uv with pre-commit
|
|
description:
|
|
A guide to using uv with pre-commit to automatically update lock files, export requirements, and
|
|
compile requirements files.
|
|
---
|
|
|
|
# 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 make sure your `uv.lock` file is up to date even if your `pyproject.toml` file was changed via
|
|
pre-commit, add the following to the `.pre-commit-config.yaml`:
|
|
|
|
```yaml title=".pre-commit-config.yaml"
|
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
# uv version.
|
|
rev: 0.5.21
|
|
hooks:
|
|
- id: uv-lock
|
|
```
|
|
|
|
To keep your `requirements.txt` file updated using pre-commit:
|
|
|
|
```yaml title=".pre-commit-config.yaml"
|
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
# uv version.
|
|
rev: 0.5.21
|
|
hooks:
|
|
- id: uv-export
|
|
```
|
|
|
|
To compile requirements via pre-commit, add the following to the `.pre-commit-config.yaml`:
|
|
|
|
```yaml title=".pre-commit-config.yaml"
|
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
# uv version.
|
|
rev: 0.5.21
|
|
hooks:
|
|
# Compile requirements
|
|
- id: pip-compile
|
|
args: [requirements.in, -o, requirements.txt]
|
|
```
|
|
|
|
To compile alternative files, modify `args` and `files`:
|
|
|
|
```yaml title=".pre-commit-config.yaml"
|
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
# uv version.
|
|
rev: 0.5.21
|
|
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:
|
|
|
|
```yaml title=".pre-commit-config.yaml"
|
|
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
# uv version.
|
|
rev: 0.5.21
|
|
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)$
|
|
```
|