Skip to content

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

@shaanmajid

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions