Skip to content

Proposal: uv-synced Python hook environments (lockfile + groups) #1675

Description

@CarliJoy

Related issues

Several issues appear to share the same missing primitive: creating/updating Python hook environments via a uv sync-style operation, instead of installing ad-hoc dependencies.


Problem

Current Python hook behaviour forces trade-offs:


Core idea

Add a uv-backed mode that:

  1. creates a dedicated hook venv (as Python hooks already do),
  2. populates it via lockfile-driven sync (uv.lock) using defined dependency groups in frozen mode.

Or put differently: make using prek with uv-based projects feel like using uv.


Option A — new language variant python-uv

Introduce a new language (name bikesheddable) meaning:

“Create and populate the hook environment using uv sync semantics.”

Example:

- repo: local
  hooks:
    - id: mypy
      name: mypy (uv-synced)
      language: python-uv
      entry: mypy
      dependency_groups: [typecheck]

Characteristics:


Option B — extend language: python with lockfile + groups/extras

Instead of a new language, extend language: python with opt-in configuration.

Example:

- repo: local
  hooks:
    - id: mypy
      language: python
      entry: mypy
      lockfile: uv.lock
      dependency_groups: [typecheck]

Semantics:

  • Setting lockfile switches environment population to uv sync-style behaviour.
  • dependency_groups / extras select what is installed.
  • Default behaviour remains unchanged if lockfile is not specified.

Lockfile handling

Initial scope:

  • Only support uv.lock.

Future extension:

  • Support additional lock formats (e.g. py.lock) without changing the high-level configuration model.

This directly addresses reproducibility concerns from #1311 while keeping the initial scope small.


Why this solves the linked issues

I tend to option A.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions