Add uv python install --default (#8650)

This pull request is best viewed with [whitespace
hidden](https://github.com/astral-sh/uv/pull/8650/files?diff=unified&w=1)

Adds a `--default` flag to `uv python install` in preview. This includes
a `python` and `python{major}` executable in addition to the
`python{major}.{minor}` executable. We will replace uv-managed
executables, but externally managed executables require the `--force`
flag to overwrite.

If you run `uv python install` (without arguments), we include the
`--default` flag implicitly to populate `python` and `python3` for the
"default" install version.

In the future, we should add a warning if the installed executable isn't
at the front of the PATH.
This commit is contained in:
Zanie Blue 2024-12-02 19:04:57 -06:00 committed by GitHub
parent 97114ebe4b
commit 63443f1984
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 500 additions and 125 deletions

View file

@ -327,8 +327,8 @@ impl PythonInstallationKey {
&self.libc
}
/// Return a canonical name for a versioned executable.
pub fn versioned_executable_name(&self) -> String {
/// Return a canonical name for a minor versioned executable.
pub fn executable_name_minor(&self) -> String {
format!(
"python{maj}.{min}{var}{exe}",
maj = self.major,
@ -337,6 +337,25 @@ impl PythonInstallationKey {
exe = std::env::consts::EXE_SUFFIX
)
}
/// Return a canonical name for a major versioned executable.
pub fn executable_name_major(&self) -> String {
format!(
"python{maj}{var}{exe}",
maj = self.major,
var = self.variant.suffix(),
exe = std::env::consts::EXE_SUFFIX
)
}
/// Return a canonical name for an un-versioned executable.
pub fn executable_name(&self) -> String {
format!(
"python{var}{exe}",
var = self.variant.suffix(),
exe = std::env::consts::EXE_SUFFIX
)
}
}
impl fmt::Display for PythonInstallationKey {