Ensure python-to-pythonX.Y symlink exists in downloaded Pythons (#5849)

## 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.
This commit is contained in:
Charlie Marsh 2024-08-06 23:03:22 -04:00 committed by GitHub
parent e58c503f65
commit d0b16f9018
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

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