Skip to content

Retry with inferred Python constraint on uv pip install failure #1618

Open

Description

@shaanmajid

Follow-up to #1594, #1596.

prek resolves the Python version for hook venvs using: PEP 723 > user config > requires-python from pyproject.toml > default (Any) (i.e. let uv decide). This works when the hook or repo explicitly declares its Python requirement, but doesn't handle transitive constraints — when a hook's deps require a narrower range than what's declared, or nothing is declared at all.

Example: hook foo has no requires-python, but its dep bar requires >=3.10. prek can't know this upfront, so uv's default version selection is used when calling uv venv create. Depending on previously installed uv versions, the venv may be created with a Python that's too old and uv pip install fails.

uv handles this in uvx/uv tool install via refine_interpreter(): when resolution fails with NoSolution, it extracts a Python bound from the error, recreates the environment, and retries. The retry is cheap since uv's HTTP cache already has all the metadata from the failed attempt. It's heuristic and can miss edge cases, but prek could adopt the same pattern as a fallback.

Activity

  1. changed the title [-]Infer Python version from resolver errors and retry venv creation[/-] [+]Retry with inferred Python constraint on uv pip install failure[/+] on Feb 10, 2026
  2. added 6 commits that reference this issue on Jul 24, 2026
    324ee60
    4eb0dbb
    c1dc7ef
    54a7ae3
    141471d
    b426e22
  3. added 7 commits that reference this issue on Oct 8, 2026
    bb45de2
    0df0f41
    5182940
    91c2a4e
    4daaeb7
    15bb34b
    21f8b1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions