Skip to content

Add uv tool list --show-python to show python version#15312

Closed
pythonweb2 wants to merge 7 commits intoastral-sh:mainfrom
pythonweb2:uv-tool-add-python-list-option
Closed

Add uv tool list --show-python to show python version#15312
pythonweb2 wants to merge 7 commits intoastral-sh:mainfrom
pythonweb2:uv-tool-add-python-list-option

Conversation

@pythonweb2
Copy link
Contributor

@pythonweb2 pythonweb2 commented Aug 15, 2025

Summary

Display information about the python version when using the uv tool list cli command.

Test Plan

Added a test that tests the option, and then also a test that tests all of the --show-* options in the command.

@zanieb
Copy link
Member

zanieb commented Aug 15, 2025

We'll need a test case in it/tool_list too

@pythonweb2
Copy link
Contributor Author

I added tests @zanieb and made some changes in where the version gets pulled from. Lmk if it looks OK.

.unwrap_or_default();

let python_version = if show_python {
match installed_tools.get_environment(&name, cache) {
Copy link
Member

@zanieb zanieb Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. I'm surprised we don't need to read the environment elsewhere here.

installed_tools.version(&name, cache) reads the environment. We probably don't want to do that multiple times.
I think might want to get the environment above and re-use it for both of these operations. That'll be more performant and we don't need to handle error cases multiple times.

I'd probably do something like...

  • Add a new ToolEnvironment type that's returned from get_environment. It can just wrap PythonEnvironment. You can implement deref, into_inner, etc. (see other patterns like that) so it's not annoying to work with. There are only a few callsites so this shouldn't be bad.
  • Move the InstalledTools::version function to ToolEnvironment. There are also only a couple call-sites to update here too.
  • Now in this function, get the environment once, then derive the tool and interpreter versions from it.

match installed_tools.get_environment(&name, cache) {
Ok(Some(env)) => {
let interpreter = env.interpreter();
format!(" [{}]", interpreter.markers().implementation_version())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just use interpreter.python_full_version(). I think we also probably want to include the implementation name. e.g., CPython 3.13.1.

Copy link
Member

@zanieb zanieb Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could display [python: <version>]. I don't know if I feel strongly. That'd be consistent with the other displays? but [python: <implementation> <version>] feels too verbose.

Copy link
Contributor Author

@pythonweb2 pythonweb2 Aug 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought that [python: ... felt verbose as well. If the implementation is added, is seems like that would be self-explanatory enough.

let interpreter = env.interpreter();
format!(" [{}]", interpreter.markers().implementation_version())
}
Ok(None) => String::from(" [python: not found]"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should skip display of the entire tool if the environment is missing. That should be resolve by the refactor I suggested.

format!(" [{}]", interpreter.markers().implementation_version())
}
Ok(None) => String::from(" [python: not found]"),
Err(e) => format!(" [python: error: {e}]"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want to display this as a warning as done for tool version handling — this should also be resolved by the refactor.

@pythonweb2 pythonweb2 deleted the uv-tool-add-python-list-option branch October 10, 2025 17:43
pull bot pushed a commit to dpprdan/uv that referenced this pull request Oct 10, 2025
<!--
Thank you for contributing to uv! To help us out with reviewing, please
consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

Closes astral-sh#15312 
Closes astral-sh#16237

---------

Co-authored-by: pythonweb2 <[email protected]>
Co-authored-by: Wade Roberts <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants