From d0b16f90185ca7783d114306ade1626156ea6e29 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 6 Aug 2024 23:03:22 -0400 Subject: [PATCH] Ensure `python`-to-`pythonX.Y` symlink exists in downloaded Pythons (#5849) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary After installing: ``` ❯ readlink "/Users/crmarsh/Library/Application Support/uv/python/cpython-3.12.4-macos-aarch64-none/bin/python" python3.12 ❯ readlink "/Users/crmarsh/Library/Application Support/uv/python/cpython-3.9.5-macos-aarch64-none/bin/python" python3.9 ``` Closes https://github.com/astral-sh/uv/issues/5838. --- crates/uv-python/src/downloads.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/uv-python/src/downloads.rs b/crates/uv-python/src/downloads.rs index ff4287a26..59dd62598 100644 --- a/crates/uv-python/src/downloads.rs +++ b/crates/uv-python/src/downloads.rs @@ -495,6 +495,21 @@ impl ManagedPythonDownload { extracted = extracted.join("install"); } + // If the distribution is missing a `python`-to-`pythonX.Y` symlink, add it. PEP 394 permits + // it, and python-build-standalone releases after `20240726` include it, but releases prior + // to that date do not. + #[cfg(unix)] + { + match std::os::unix::fs::symlink( + format!("python{}.{}", self.key.major, self.key.minor), + extracted.join("bin").join("python"), + ) { + Ok(()) => {} + Err(err) if err.kind() == io::ErrorKind::AlreadyExists => {} + Err(err) => return Err(err.into()), + } + } + // Persist it to the target debug!("Moving {} to {}", extracted.display(), path.user_display()); rename_with_retry(extracted, &path)