You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 <<EOFheredoc> [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 7msAudited in 0.02ms
The text was updated successfully, but these errors were encountered:
mjpieters
changed the title
Automatically install and use an older uv version to satisfy requires-version.
Automatically install and use a matching uv version to satisfy requires-version.
Jan 29, 2025
alias uv='uv tool run --with "uv$(yq -r '\''.tool.uv.required-version // ""'\'' pyproject.toml)" uv'
(which requires that you have yq installed, and only works if you are currently in the same directory as the pyproject.toml file, and won't work if you use uv.toml files).
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 recentuv
version installed. This can lead to problems:We can set
required-version
to prevent using newer uv versions:but then anyone with a newer
uv
can't update the lockfile asuv
currently will exit with an error when encountering arequired-version
pin that doesn't match its own version. UNLESS they useuv tool run
to install the olderuv
version to do the work:Could
uv
do this directly please? Specifically, when therequired-version
requirement can't be met by the currentuv
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 therequired-version
requirements for the current project, instead of exiting with an error,uv
finds a version of itself that does satisfy the requirements:The text was updated successfully, but these errors were encountered: