-
-
Notifications
You must be signed in to change notification settings - Fork 169
Description
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.