-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Respect global Python version pins in uv tool run
and uv tool install
#14112
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
base: main
Are you sure you want to change the base?
Conversation
1a8ba14
to
c421cb9
Compare
// Allow the existing environment if the user didn't explicitly request another | ||
// version | ||
if let Some(ref tool_receipt) = existing_tool_receipt { | ||
if settings.reinstall.is_all() && tool_receipt.python().is_none() && python_request.is_some() { | ||
let _ = writeln!( | ||
printer.stderr(), | ||
"Ignoring existing environment for `{from}`: the Python interpreter does not match the environment interpreter", | ||
from = from.name.cyan(), | ||
); | ||
false | ||
} else { | ||
true | ||
} | ||
} else { | ||
true | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be refactored to avoid the repeated else
branches, but the logic should be correct. The comment needs more detail.
@jtfmumm want to give this a look and see if we're aligned on the behavior? |
The behavior makes sense to me, and is consistent with how I was thinking about it before. |
Closes #12921
For
uv tool run
, we'll just use the global Python version for all invocations without an explicit alternative request (i.e., via the--python
flag).For
uv tool install
, it's a bit more complicated:--reinstall
or--python
is used--python
, we won't use the global Python version, unless the tool is uninstalled firstThe behavior can be demonstrated as follows
This is a little more complicated than always reinstalling when the global Python version pin changes, but I think it's probably more intuitive when actually using the tool. We briefly touched on this when adding global version pins at #12115 (comment)
Minor note: I need to do a self-review of this implementation, as it's a little awkward to encode this behavior in the existing logic.