Skip to content

Conversation

zanieb
Copy link
Member

@zanieb zanieb commented Jun 17, 2025

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:

  • If the tool is not installed, we'll use the global Python version
  • If the tool is already installed, we won't change the Python version unless --reinstall or --python is used
  • If the tool was installed with --python, we won't use the global Python version, unless the tool is uninstalled first

The behavior can be demonstrated as follows

$ uv python pin --global 3.12
$ uv tool install flask  # uses 3.12
$ uv tool install flask  # no-op
$ uv python pin --global 3.13
$ uv tool install flask  # no-op
$ uv tool install flask --reinstall  # uses 3.13
$ uv tool install flask -p 3.12 # uses 3.12
$ uv tool install flask  # no-op
$ uv tool install flask --reinstall # uses 3.12

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.

@zanieb zanieb added the bug Something isn't working label Jun 17, 2025
@zanieb zanieb force-pushed the zb/tool-pyver branch 2 times, most recently from 1a8ba14 to c421cb9 Compare June 18, 2025 01:16
Comment on lines 393 to 401
// 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
}
Copy link
Member Author

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.

@zanieb
Copy link
Member Author

zanieb commented Jun 20, 2025

@jtfmumm want to give this a look and see if we're aligned on the behavior?

@zanieb zanieb temporarily deployed to uv-test-registries June 20, 2025 20:40 — with GitHub Actions Inactive
@jtfmumm
Copy link
Contributor

jtfmumm commented Jun 26, 2025

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

@zanieb zanieb temporarily deployed to uv-test-registries October 8, 2025 15:07 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Respect --global Python pins during uv tool operations

2 participants