Improve reporting of managed interpreter symlinks in uv python list#18459
Improve reporting of managed interpreter symlinks in uv python list#18459zanieb merged 9 commits intoastral-sh:mainfrom
uv python list#18459Conversation
When `--managed-python` is used, widen discovery to include search path sources so that symlinks pointing to managed installations are found, then post-filter to keep only managed interpreters. Previously, `OnlyManaged` only searched the `Managed` source, missing symlinks in `~/.local/bin/` and similar PATH directories that point to uv-managed Python installations. Fixes astral-sh#17959 https://claude.ai/code/session_01Q6Uo1r3YhrdCWyKPXB5X5R
Extend the post-filter to handle both directions: `--managed-python` keeps only managed interpreters, and `--no-managed-python` excludes managed interpreters (e.g., symlinks on the search path that point to uv-managed installations). https://claude.ai/code/session_01Q6Uo1r3YhrdCWyKPXB5X5R
The previous test used `with_versions_as_managed` which changes the discovery source to `Managed` — bypassing the search path symlink scenario. The new test uses `python install` to create real symlinks in `bin_dir`, then adds `bin_dir` to `UV_TEST_PYTHON_PATH` to verify that `--no-managed-python` correctly excludes symlinks pointing to managed installations, and `--managed-python` includes them. https://claude.ai/code/session_01Q6Uo1r3YhrdCWyKPXB5X5R
Merging this PR will degrade performance by 5.49%
Performance Changes
Comparing |
1 similar comment
Merging this PR will degrade performance by 5.49%
Performance Changes
Comparing |
| .filter(|installation| match python_preference { | ||
| PythonPreference::OnlyManaged => installation.interpreter().is_managed(), | ||
| PythonPreference::OnlySystem => !installation.interpreter().is_managed(), | ||
| PythonPreference::Managed | PythonPreference::System => true, |
There was a problem hiding this comment.
Can this just be python_preference.allows(installation.source)?
There was a problem hiding this comment.
No, here we want to check if the installation is managed regardless of the source, so we need to actually check where interpreter's base prefix is. It does seem like PythonPreference::allows_interpreter would be useful though.
Closes #17959
Expands discovery to always include a system scan even if
--managed-pythonis used to find links to managed interpreters on thePATH. Then filters reported interpreters by whether or not they are managed after discovery, so--no-managed-pythonwill never report those symlinks.