Allow configuring the toolchain fetch strategy (#4601)

Adds a `toolchain-fetch` option alongside `toolchain-preference` with
`automatic` (default) and `manual` values allowing automatic toolchain
fetches to be disabled (replaces
https://github.com/astral-sh/uv/pull/4425). When `manual`, toolchains
must be installed with `uv toolchain install`.

Note this was previously implemented with `if-necessary`, `always`,
`never` variants but the interaction between this and
`toolchain-preference` was too confusing. By reducing to a binary
option, things should be clearer. The `if-necessary` behavior moved to
`toolchain-preference=installed`. See
https://github.com/astral-sh/uv/pull/4601#discussion_r1657839633 and
https://github.com/astral-sh/uv/pull/4601#discussion_r1658658755
This commit is contained in:
Zanie Blue 2024-07-01 21:54:24 -04:00 committed by GitHub
parent ec2723a9f5
commit 6799cc883a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 219 additions and 89 deletions

View file

@ -13,7 +13,7 @@ use uv_configuration::{
};
use uv_normalize::{ExtraName, PackageName};
use uv_resolver::{AnnotationStyle, ExcludeNewer, PreReleaseMode, ResolutionMode};
use uv_toolchain::{PythonVersion, ToolchainPreference};
use uv_toolchain::{PythonVersion, ToolchainFetch, ToolchainPreference};
pub mod compat;
pub mod options;
@ -118,10 +118,14 @@ pub struct GlobalArgs {
#[arg(global = true, long, overrides_with("offline"), hide = true)]
pub no_offline: bool,
/// Whether to use system or uv-managed Python toolchains.
/// Whether to prefer Python toolchains from uv or on the system.
#[arg(global = true, long)]
pub toolchain_preference: Option<ToolchainPreference>,
/// Whether to automatically download Python toolchains when required.
#[arg(global = true, long)]
pub toolchain_fetch: Option<ToolchainFetch>,
/// Whether to enable experimental, preview features.
#[arg(global = true, long, hide = true, env = "UV_PREVIEW", value_parser = clap::builder::BoolishValueParser::new(), overrides_with("no_preview"))]
pub preview: bool,