uv/docs/guides/integration/pre-commit.md
Zanie Blue dd1934c9c3
Bump version to 0.3.0 (#6260)
[Rendered](https://github.com/astral-sh/uv/blob/zb/030/CHANGELOG.md#030)

---------

Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
2024-08-20 12:29:58 -05:00

1.3 KiB

Using uv in pre-commit

An official pre-commit hook is provided at astral-sh/uv-pre-commit.

To compile requirements via pre-commit, add the following to the .pre-commit-config.yaml:

- repo: https://github.com/astral-sh/uv-pre-commit
  # uv version.
  rev: 0.3.0
  hooks:
    # Compile requirements
    - id: pip-compile
      args: [requirements.in, -o, requirements.txt]

To compile alternative files, modify args and files:

- repo: https://github.com/astral-sh/uv-pre-commit
  # uv version.
  rev: 0.3.0
  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:

- repo: https://github.com/astral-sh/uv-pre-commit
  # uv version.
  rev: 0.3.0
  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)$