From 720ae195a1b246908961cb6e1af7a44c0599300a Mon Sep 17 00:00:00 2001 From: Di-Is Date: Mon, 15 Jul 2024 01:14:57 +0900 Subject: [PATCH] Respect the libc of the execution environment with `uv python list` (#5036) Fix #4988 ## Summary Running `uv python list` on glibc-based Linux will list musl pythons. ```bash $ uv version uv 0.2.24 $ uv python list warning: `uv python list` is experimental and may change without warning. cpython-3.12.3-linux-x86_64-musl cpython-3.12.3-linux-x86_64-gnu /usr/bin/python3 cpython-3.12.3-linux-x86_64-gnu /bin/python3 cpython-3.11.9-linux-x86_64-musl cpython-3.10.14-linux-x86_64-musl cpython-3.9.19-linux-x86_64-musl cpython-3.8.19-linux-x86_64-musl cpython-3.7.9-linux-x86_64-musl ``` Change it to show Python matching the environment's libc as follows. ```bash $ uv python list warning: `uv python list` is experimental and may change without warning. cpython-3.12.3-linux-x86_64-gnu /usr/bin/python3 cpython-3.12.3-linux-x86_64-gnu /bin/python3 cpython-3.12.3-linux-x86_64-gnu cpython-3.11.9-linux-x86_64-gnu cpython-3.10.14-linux-x86_64-gnu cpython-3.9.19-linux-x86_64-gnu cpython-3.8.19-linux-x86_64-gnu cpython-3.7.9-linux-x86_64-gnu ``` Also, if --all-platforms is specified, change to list Python for all architectures and libc. ```bash $ uv python list --all-platforms warning: `uv python list` is experimental and may change without warning. cpython-3.12.3-windows-x86_64-none cpython-3.12.3-windows-x86-none cpython-3.12.3-macos-x86_64-none cpython-3.12.3-macos-aarch64-none cpython-3.12.3-linux-x86_64-musl cpython-3.12.3-linux-x86_64-gnu /usr/bin/python3 cpython-3.12.3-linux-x86_64-gnu /bin/python3 cpython-3.12.3-linux-x86_64-gnu cpython-3.12.3-linux-s390x-gnu cpython-3.12.3-linux-powerpc64le-gnu cpython-3.12.3-linux-armv7-gnueabihf cpython-3.12.3-linux-armv7-gnueabi cpython-3.12.3-linux-aarch64-gnu ... ``` ## Test Plan The following commands were executed on the command line to confirm the results in Ubuntu 24.04. - `cargo run python list` - `cargo run python list --all-platforms` --- crates/uv-python/src/downloads.rs | 5 +++++ crates/uv/src/commands/python/list.rs | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/uv-python/src/downloads.rs b/crates/uv-python/src/downloads.rs index 3c02f8f6c..6bf5c08b0 100644 --- a/crates/uv-python/src/downloads.rs +++ b/crates/uv-python/src/downloads.rs @@ -233,6 +233,11 @@ impl PythonDownloadRequest { return false; } } + if let Some(libc) = &self.libc { + if key.libc != *libc { + return false; + } + } if let Some(implementation) = &self.implementation { if key.implementation != LenientImplementationName::from(*implementation) { return false; diff --git a/crates/uv/src/commands/python/list.rs b/crates/uv/src/commands/python/list.rs index 69baf30b6..e32762576 100644 --- a/crates/uv/src/commands/python/list.rs +++ b/crates/uv/src/commands/python/list.rs @@ -113,14 +113,15 @@ pub(crate) async fn list( // Only show the latest patch version for each download unless all were requested if !matches!(kind, Kind::System) { if let [major, minor, ..] = version.release() { - if !seen_minor.insert((os.clone(), *major, *minor)) { + if !seen_minor.insert((os.clone(), *major, *minor, *key.arch(), *key.libc())) { if matches!(kind, Kind::Download) && !all_versions { continue; } } } if let [major, minor, patch] = version.release() { - if !seen_patch.insert((os.clone(), *major, *minor, *patch)) { + if !seen_patch.insert((os.clone(), *major, *minor, *patch, *key.arch(), key.libc())) + { if matches!(kind, Kind::Download) { continue; }