Skip to content

Commit

Permalink
Add uv python install --default
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Nov 27, 2024
1 parent b503a25 commit 44b018a
Show file tree
Hide file tree
Showing 9 changed files with 412 additions and 122 deletions.
15 changes: 15 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4214,6 +4214,21 @@ pub struct PythonInstallArgs {
/// Implies `--reinstall`.
#[arg(long, short)]
pub force: bool,

/// Use as the default Python version.
///
/// By default, only a `python{major}.{minor}` executable is installed, e.g., `python3.10`. When
/// the `--default` flag is used, `python{major}`, e.g., `python3`, and `python` executables are
/// also installed.
///
/// Alternative Python variants will still include their tag. For example, installing
/// 3.13+freethreaded with `--default` will include in `python3t` and `pythont`, not `python3`
/// and `python`.
///
/// If multiple Python versions are requested during the installation, the first request will be
/// the default.
#[arg(long)]
pub default: bool,
}

#[derive(Args)]
Expand Down
23 changes: 21 additions & 2 deletions crates/uv-python/src/installation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Loading

0 comments on commit 44b018a

Please sign in to comment.