Skip to content

Commit

Permalink
Drop prefer prefix from toolchain-preference values (#4602)
Browse files Browse the repository at this point in the history
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
#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.
  • Loading branch information
zanieb authored Jul 2, 2024
1 parent 6799cc8 commit c0a06a2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
29 changes: 15 additions & 14 deletions crates/uv-toolchain/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,20 @@ pub enum ToolchainRequest {
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum ToolchainPreference {
/// Only use managed toolchains, never use system toolchains.
/// Only use managed toolchains; never use system toolchains.
OnlyManaged,
/// Prefer installed toolchains, only download managed toolchains if no system toolchain is found.
///
/// Installed managed toolchains are still preferred over system toolchains.
#[default]
Installed,
/// Prefer managed toolchains over system toolchains, even if one needs to be downloaded.
PreferManaged,
/// Prefer system toolchains, only use managed toolchains if no system toolchain is found.
PreferSystem,
/// Only use system toolchains, never use managed toolchains.
/// Prefer managed toolchains over system toolchains, even if fetching is required.
Managed,
/// Prefer system toolchains over 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,
}

Expand Down Expand Up @@ -313,12 +317,12 @@ fn python_executables_from_installed<'a>(

match preference {
ToolchainPreference::OnlyManaged => Box::new(from_managed_toolchains),
ToolchainPreference::PreferManaged | ToolchainPreference::Installed => Box::new(
ToolchainPreference::Managed | ToolchainPreference::Installed => Box::new(
from_managed_toolchains
.chain(from_search_path)
.chain(from_py_launcher),
),
ToolchainPreference::PreferSystem => Box::new(
ToolchainPreference::System => Box::new(
from_search_path
.chain(from_py_launcher)
.chain(from_managed_toolchains),
Expand Down Expand Up @@ -1153,7 +1157,7 @@ impl ToolchainPreference {

match self {
ToolchainPreference::OnlyManaged => matches!(source, ToolchainSource::Managed),
Self::PreferManaged | Self::PreferSystem | Self::Installed => matches!(
Self::Managed | Self::System | Self::Installed => matches!(
source,
ToolchainSource::Managed
| ToolchainSource::SearchPath
Expand Down Expand Up @@ -1181,10 +1185,7 @@ impl ToolchainPreference {
}

pub(crate) fn allows_managed(self) -> bool {
matches!(
self,
Self::PreferManaged | Self::OnlyManaged | Self::Installed
)
matches!(self, Self::Managed | Self::OnlyManaged | Self::Installed)
}
}

Expand Down Expand Up @@ -1491,7 +1492,7 @@ impl fmt::Display for ToolchainPreference {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let s = match self {
Self::OnlyManaged => "managed toolchains",
Self::PreferManaged | Self::Installed | Self::PreferSystem => {
Self::Managed | Self::Installed | Self::System => {
if cfg!(windows) {
"managed toolchains, system path, or `py` launcher"
} else {
Expand Down
4 changes: 1 addition & 3 deletions crates/uv-toolchain/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ impl Toolchain {
let request = request.unwrap_or_default();

// Perform a fetch aggressively if managed toolchains are preferred
if matches!(preference, ToolchainPreference::PreferManaged)
&& toolchain_fetch.is_automatic()
{
if matches!(preference, ToolchainPreference::Managed) && toolchain_fetch.is_automatic() {
if let Some(request) = PythonDownloadRequest::try_from_request(&request) {
return Self::fetch(request, client_builder, cache).await;
}
Expand Down
2 changes: 1 addition & 1 deletion crates/uv/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ pub fn python_toolchains_for_versions(
if let Ok(toolchain) = Toolchain::find(
&ToolchainRequest::parse(python_version),
EnvironmentPreference::OnlySystem,
ToolchainPreference::PreferManaged,
ToolchainPreference::Managed,
&cache,
) {
toolchain.into_interpreter().sys_executable().to_owned()
Expand Down
14 changes: 7 additions & 7 deletions uv.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0a06a2

Please sign in to comment.