Skip to content

Commit 63443f1

Browse files
authored
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.
1 parent 97114eb commit 63443f1

File tree

9 files changed

+497
-122
lines changed

9 files changed

+497
-122
lines changed

crates/uv-cli/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -4226,6 +4226,21 @@ pub struct PythonInstallArgs {
42264226
/// Implies `--reinstall`.
42274227
#[arg(long, short)]
42284228
pub force: bool,
4229+
4230+
/// Use as the default Python version.
4231+
///
4232+
/// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
4233+
/// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
4234+
/// also installed.
4235+
///
4236+
/// Alternative Python variants will still include their tag. For example, installing
4237+
/// 3.13+freethreaded with `--default` will include in `python3t` and `pythont`, not `python3`
4238+
/// and `python`.
4239+
///
4240+
/// If multiple Python versions are requested during the installation, the first request will be
4241+
/// the default.
4242+
#[arg(long)]
4243+
pub default: bool,
42294244
}
42304245

42314246
#[derive(Args)]

crates/uv-python/src/installation.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ impl PythonInstallationKey {
327327
&self.libc
328328
}
329329

330-
/// Return a canonical name for a versioned executable.
331-
pub fn versioned_executable_name(&self) -> String {
330+
/// Return a canonical name for a minor versioned executable.
331+
pub fn executable_name_minor(&self) -> String {
332332
format!(
333333
"python{maj}.{min}{var}{exe}",
334334
maj = self.major,
@@ -337,6 +337,25 @@ impl PythonInstallationKey {
337337
exe = std::env::consts::EXE_SUFFIX
338338
)
339339
}
340+
341+
/// Return a canonical name for a major versioned executable.
342+
pub fn executable_name_major(&self) -> String {
343+
format!(
344+
"python{maj}{var}{exe}",
345+
maj = self.major,
346+
var = self.variant.suffix(),
347+
exe = std::env::consts::EXE_SUFFIX
348+
)
349+
}
350+
351+
/// Return a canonical name for an un-versioned executable.
352+
pub fn executable_name(&self) -> String {
353+
format!(
354+
"python{var}{exe}",
355+
var = self.variant.suffix(),
356+
exe = std::env::consts::EXE_SUFFIX
357+
)
358+
}
340359
}
341360

342361
impl fmt::Display for PythonInstallationKey {

0 commit comments

Comments
 (0)