Drop prefer prefix from toolchain-preference values (#4602)

I think `--toolchain-preference system` is sufficiently clear and
`--toolchain-preference prefer-system` is excessively verbose. This was
discussed in the original pull request at
https://github.com/astral-sh/uv/pull/4424 but because we had a case for
preferring "installed managed" toolchains I was hesitant to change it.
Now that I've dropped that in #4601, I think we can drop the prefix.
This commit is contained in:
Zanie Blue 2024-07-01 22:07:30 -04:00 committed by GitHub
parent 6799cc883a
commit c0a06a2c1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 25 deletions

View file

@ -57,16 +57,20 @@ pub enum ToolchainRequest {
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))] #[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] #[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum ToolchainPreference { pub enum ToolchainPreference {
/// Only use managed toolchains, never use system toolchains. /// Only use managed toolchains; never use system toolchains.
OnlyManaged, OnlyManaged,
/// Prefer installed toolchains, only download managed toolchains if no system toolchain is found. /// Prefer installed toolchains, only download managed toolchains if no system toolchain is found.
///
/// Installed managed toolchains are still preferred over system toolchains.
#[default] #[default]
Installed, Installed,
/// Prefer managed toolchains over system toolchains, even if one needs to be downloaded. /// Prefer managed toolchains over system toolchains, even if fetching is required.
PreferManaged, Managed,
/// Prefer system toolchains, only use managed toolchains if no system toolchain is found. /// Prefer system toolchains over managed toolchains.
PreferSystem, ///
/// Only use system toolchains, never use managed toolchains. /// If a system toolchain cannot be found, a managed toolchain can be used.
System,
/// Only use system toolchains; never use managed toolchains.
OnlySystem, OnlySystem,
} }
@ -313,12 +317,12 @@ fn python_executables_from_installed<'a>(
match preference { match preference {
ToolchainPreference::OnlyManaged => Box::new(from_managed_toolchains), ToolchainPreference::OnlyManaged => Box::new(from_managed_toolchains),
ToolchainPreference::PreferManaged | ToolchainPreference::Installed => Box::new( ToolchainPreference::Managed | ToolchainPreference::Installed => Box::new(
from_managed_toolchains from_managed_toolchains
.chain(from_search_path) .chain(from_search_path)
.chain(from_py_launcher), .chain(from_py_launcher),
), ),
ToolchainPreference::PreferSystem => Box::new( ToolchainPreference::System => Box::new(
from_search_path from_search_path
.chain(from_py_launcher) .chain(from_py_launcher)
.chain(from_managed_toolchains), .chain(from_managed_toolchains),
@ -1153,7 +1157,7 @@ impl ToolchainPreference {
match self { match self {
ToolchainPreference::OnlyManaged => matches!(source, ToolchainSource::Managed), ToolchainPreference::OnlyManaged => matches!(source, ToolchainSource::Managed),
Self::PreferManaged | Self::PreferSystem | Self::Installed => matches!( Self::Managed | Self::System | Self::Installed => matches!(
source, source,
ToolchainSource::Managed ToolchainSource::Managed
| ToolchainSource::SearchPath | ToolchainSource::SearchPath
@ -1181,10 +1185,7 @@ impl ToolchainPreference {
} }
pub(crate) fn allows_managed(self) -> bool { pub(crate) fn allows_managed(self) -> bool {
matches!( matches!(self, Self::Managed | Self::OnlyManaged | Self::Installed)
self,
Self::PreferManaged | Self::OnlyManaged | Self::Installed
)
} }
} }
@ -1491,7 +1492,7 @@ impl fmt::Display for ToolchainPreference {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let s = match self { let s = match self {
Self::OnlyManaged => "managed toolchains", Self::OnlyManaged => "managed toolchains",
Self::PreferManaged | Self::Installed | Self::PreferSystem => { Self::Managed | Self::Installed | Self::System => {
if cfg!(windows) { if cfg!(windows) {
"managed toolchains, system path, or `py` launcher" "managed toolchains, system path, or `py` launcher"
} else { } else {

View file

@ -88,9 +88,7 @@ impl Toolchain {
let request = request.unwrap_or_default(); let request = request.unwrap_or_default();
// Perform a fetch aggressively if managed toolchains are preferred // Perform a fetch aggressively if managed toolchains are preferred
if matches!(preference, ToolchainPreference::PreferManaged) if matches!(preference, ToolchainPreference::Managed) && toolchain_fetch.is_automatic() {
&& toolchain_fetch.is_automatic()
{
if let Some(request) = PythonDownloadRequest::try_from_request(&request) { if let Some(request) = PythonDownloadRequest::try_from_request(&request) {
return Self::fetch(request, client_builder, cache).await; return Self::fetch(request, client_builder, cache).await;
} }

View file

@ -711,7 +711,7 @@ pub fn python_toolchains_for_versions(
if let Ok(toolchain) = Toolchain::find( if let Ok(toolchain) = Toolchain::find(
&ToolchainRequest::parse(python_version), &ToolchainRequest::parse(python_version),
EnvironmentPreference::OnlySystem, EnvironmentPreference::OnlySystem,
ToolchainPreference::PreferManaged, ToolchainPreference::Managed,
&cache, &cache,
) { ) {
toolchain.into_interpreter().sys_executable().to_owned() toolchain.into_interpreter().sys_executable().to_owned()

14
uv.schema.json generated
View file

@ -1218,35 +1218,35 @@
"ToolchainPreference": { "ToolchainPreference": {
"oneOf": [ "oneOf": [
{ {
"description": "Only use managed toolchains, never use system toolchains.", "description": "Only use managed toolchains; never use system toolchains.",
"type": "string", "type": "string",
"enum": [ "enum": [
"only-managed" "only-managed"
] ]
}, },
{ {
"description": "Prefer installed toolchains, only download managed toolchains if no system toolchain is found.", "description": "Prefer installed toolchains, only download managed toolchains if no system toolchain is found.\n\nInstalled managed toolchains are still preferred over system toolchains.",
"type": "string", "type": "string",
"enum": [ "enum": [
"installed" "installed"
] ]
}, },
{ {
"description": "Prefer managed toolchains over system toolchains, even if one needs to be downloaded.", "description": "Prefer managed toolchains over system toolchains, even if fetching is required.",
"type": "string", "type": "string",
"enum": [ "enum": [
"prefer-managed" "managed"
] ]
}, },
{ {
"description": "Prefer system toolchains, only use managed toolchains if no system toolchain is found.", "description": "Prefer system toolchains over managed toolchains.\n\nIf a system toolchain cannot be found, a managed toolchain can be used.",
"type": "string", "type": "string",
"enum": [ "enum": [
"prefer-system" "system"
] ]
}, },
{ {
"description": "Only use system toolchains, never use managed toolchains.", "description": "Only use system toolchains; never use managed toolchains.",
"type": "string", "type": "string",
"enum": [ "enum": [
"only-system" "only-system"