uv/crates/uv-resolver/src/fork_strategy.rs
Charlie Marsh b2459e6326
Introduce a --fork-strategy preference mode (#9868)
## Summary

This PR makes the behavior in https://github.com/astral-sh/uv/pull/9827
the default: we try to select the latest supported package version for
each supported Python version, but we still optimize for choosing fewer
versions when stratifying by platform.

However, you can opt out with `--fork-strategy fewest`.

Closes https://github.com/astral-sh/uv/issues/7190.
2024-12-13 16:05:07 -05:00

23 lines
939 B
Rust

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, serde::Deserialize, serde::Serialize)]
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub enum ForkStrategy {
/// Optimize for selecting the fewest number of versions for each package. Older versions may
/// be preferred if they are compatible with a wider range of supported Python versions or
/// platforms.
Fewest,
/// Optimize for selecting latest supported version of each package, for each supported Python
/// version.
#[default]
RequiresPython,
}
impl std::fmt::Display for ForkStrategy {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Fewest => write!(f, "fewest"),
Self::RequiresPython => write!(f, "requires-python"),
}
}
}