Skip to content

Automatically install and use a matching uv version to satisfy requires-version. #11065

@mjpieters

Description

@mjpieters

Summary

We have some projects running with an older, pinned uv version in docker containers, but the lock file is updated by developers with the most recent uv version installed. This can lead to problems:

  • 0.5.19 added support for omitting dynamic package versions from the lock file. We have some projects with such dynamic versions, but locking with 0.5.19 or newer makes the lock file unreadable by older uv versions.
  • If a 0.6.x version was released with explicit backward compatibility conflicts, we'd be further up the creek without a paddle.

We can set required-version to prevent using newer uv versions:

[tool.uv]
required-version = ">=0.5.0,<0.5.19"

but then anyone with a newer uv can't update the lockfile as uv currently will exit with an error when encountering a required-version pin that doesn't match its own version. UNLESS they use uv tool run to install the older uv version to do the work:

% uv lock
error: Required uv version `>=0.5.0, <0.5.19` does not match the running version `0.5.25`
% uv tool run --with 'uv>=0.5.0,<0.5.19' uv lock
Resolved 149 packages in 994ms

Could uv do this directly please? Specifically, when the required-version requirement can't be met by the current uv version, uv finds a version of itself that does match the requirement and run the desired command with that version instead.

Example

When running uv with a version that doesn't satisfy the required-version requirements for the current project, instead of exiting with an error, uv finds a version of itself that does satisfy the requirements:

% cd "$(mktemp -d)"
% uv init
Initialized project `tmp-luczgh2pmf`
% cat >>pyproject.toml <<EOF
heredoc> [tool.uv]
heredoc> required-version=">=0.5.0,<0.5.19"
heredoc> EOF
% uv sync   # executes as `uv tool run --with "uv$(yq -r '.tool.uv.required-version // ""' pyproject.toml)" uv sync`
Resolved 1 package in 7ms
Audited in 0.02ms

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement to existing functionalitywishNot on the immediate roadmap

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions