Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mjpieters opened this issue Jan 29, 2025 · 2 comments
Labels
enhancement New feature or improvement to existing functionality wish Not on the immediate roadmap

Comments

@mjpieters
Copy link
Contributor

mjpieters commented Jan 29, 2025

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
@mjpieters mjpieters added the enhancement New feature or improvement to existing functionality label Jan 29, 2025
@mjpieters 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
@mjpieters
Copy link
Contributor Author

mjpieters commented Jan 29, 2025

Our current work-around is to alias uv:

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).

@zanieb zanieb added the wish Not on the immediate roadmap label Jan 29, 2025
@zanieb
Copy link
Member

zanieb commented Jan 29, 2025

This sounds cool, but isn't something I can prioritize right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement to existing functionality wish Not on the immediate roadmap
Projects
None yet
Development

No branches or pull requests

2 participants