Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 25 additions & 9 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use uv_pypi_types::VerbatimParsedUrl;
use uv_python::{PythonDownloads, PythonPreference, PythonVersion};
use uv_redacted::DisplaySafeUrl;
use uv_resolver::{
AnnotationStyle, ExcludeNewerPackageEntry, ExcludeNewerValue, ForkStrategy, PrereleaseMode,
AnnotationStyle, ExcludeNewerOverride, ExcludeNewerPackageEntry, ForkStrategy, PrereleaseMode,
ResolutionMode,
};
use uv_settings::PythonInstallMirrors;
Expand Down Expand Up @@ -3284,8 +3284,10 @@ pub struct VenvArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
pub exclude_newer: Option<ExcludeNewerValue>,
pub exclude_newer: Option<ExcludeNewerOverride>,

/// Limit candidate packages for a specific package to those that were uploaded prior to the
/// given date.
Expand Down Expand Up @@ -5205,8 +5207,10 @@ pub struct FormatArgs {
/// Accepts a superset of [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.html) (e.g.,
/// `2006-12-02T02:07:43Z`) or local date in the same format (e.g. `2006-12-02`), as well as
/// durations relative to "now" (e.g., `-1 week`).
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER)]
pub exclude_newer: Option<ExcludeNewerValue>,
pub exclude_newer: Option<ExcludeNewerOverride>,

/// Additional arguments to pass to Ruff.
///
Expand Down Expand Up @@ -6110,8 +6114,10 @@ pub struct ToolListArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
pub exclude_newer: Option<ExcludeNewerValue>,
pub exclude_newer: Option<ExcludeNewerOverride>,

// Hide unused global Python options.
#[arg(long, hide = true)]
Expand Down Expand Up @@ -6373,8 +6379,10 @@ pub struct ToolUpgradeArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
pub exclude_newer: Option<ExcludeNewerValue>,
pub exclude_newer: Option<ExcludeNewerOverride>,

/// Limit candidate packages for specific packages to those that were uploaded prior to the
/// given date.
Expand Down Expand Up @@ -7444,8 +7452,10 @@ pub struct InstallerArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
exclude_newer: Option<ExcludeNewerValue>,
exclude_newer: Option<ExcludeNewerOverride>,

/// Limit candidate packages for specific packages to those that were uploaded prior to the
/// given date.
Expand Down Expand Up @@ -7691,8 +7701,10 @@ pub struct ResolverArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
exclude_newer: Option<ExcludeNewerValue>,
exclude_newer: Option<ExcludeNewerOverride>,

/// Limit candidate packages for specific packages to those that were uploaded prior to the
/// given date.
Expand Down Expand Up @@ -7936,13 +7948,15 @@ pub struct ResolverInstallerArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(
long,
env = EnvVars::UV_EXCLUDE_NEWER,
help_heading = "Resolver options",
value_hint = ValueHint::Other,
)]
pub exclude_newer: Option<ExcludeNewerValue>,
pub exclude_newer: Option<ExcludeNewerOverride>,

/// Limit candidate packages for specific packages to those that were uploaded prior to the
/// given date.
Expand Down Expand Up @@ -8071,8 +8085,10 @@ pub struct FetchArgs {
/// Durations do not respect semantics of the local time zone and are always resolved to a fixed
/// number of seconds assuming that a day is 24 hours (e.g., DST transitions are ignored).
/// Calendar units such as months and years are not allowed.
///
/// Use `false` to disable `exclude-newer`.
#[arg(long, env = EnvVars::UV_EXCLUDE_NEWER, help_heading = "Resolver options")]
exclude_newer: Option<ExcludeNewerValue>,
exclude_newer: Option<ExcludeNewerOverride>,
}

#[derive(Args)]
Expand Down
8 changes: 3 additions & 5 deletions crates/uv-cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use anstream::eprintln;
use uv_cache::Refresh;
use uv_configuration::{BuildIsolation, Reinstall, Upgrade};
use uv_distribution_types::{ConfigSettings, Index, PackageConfigSettings, Requirement};
use uv_resolver::{ExcludeNewer, ExcludeNewerPackage, PrereleaseMode};
use uv_resolver::{ExcludeNewerPackage, PrereleaseMode};
use uv_settings::{Combine, EnvFlag, PipOptions, ResolverInstallerOptions, ResolverOptions};
use uv_warnings::owo_colors::OwoColorize;

Expand Down Expand Up @@ -584,10 +584,8 @@ pub fn resolver_options(
),
extra_build_dependencies: None,
extra_build_variables: None,
exclude_newer: ExcludeNewer::from_args(
exclude_newer,
exclude_newer_package.unwrap_or_default(),
),
exclude_newer,
exclude_newer_package: exclude_newer_package.map(ExcludeNewerPackage::from_iter),
link_mode,
torch_backend: None,
no_build: flag(no_build, build, "build"),
Expand Down
32 changes: 30 additions & 2 deletions crates/uv-distribution-types/src/exclude_newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,34 @@ pub enum ExcludeNewerOverride {
Enabled(Box<ExcludeNewerValue>),
}

impl ExcludeNewerOverride {
/// Return the configured cutoff, or `None` if `exclude-newer` is disabled.
pub fn into_value(self) -> Option<ExcludeNewerValue> {
match self {
Self::Disabled => None,
Self::Enabled(value) => Some(*value),
}
}
}

impl From<ExcludeNewerValue> for ExcludeNewerOverride {
fn from(value: ExcludeNewerValue) -> Self {
Self::Enabled(Box::new(value))
}
}

impl FromStr for ExcludeNewerOverride {
type Err = String;

fn from_str(input: &str) -> Result<Self, Self::Err> {
if input == "false" {
Ok(Self::Disabled)
} else {
ExcludeNewerValue::from_str(input).map(Self::from)
}
}
}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for ExcludeNewerOverride {
fn schema_name() -> Cow<'static, str> {
Expand Down Expand Up @@ -351,8 +379,8 @@ impl<'de> serde::Deserialize<'de> for ExcludeNewerOverride {
E: serde::de::Error,
{
ExcludeNewerValue::from_str(v)
.map(|ts| ExcludeNewerOverride::Enabled(Box::new(ts)))
.map_err(|e| E::custom(format!("failed to parse exclude-newer value: {e}")))
.map(ExcludeNewerOverride::from)
.map_err(E::custom)
}

fn visit_bool<E>(self, v: bool) -> Result<Self::Value, E>
Expand Down
3 changes: 2 additions & 1 deletion crates/uv-resolver/src/exclude_newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,9 +433,10 @@ impl ExcludeNewer {

/// Create from CLI arguments.
pub fn from_args(
global: Option<ExcludeNewerValue>,
global: Option<ExcludeNewerOverride>,
package: Vec<ExcludeNewerPackageEntry>,
) -> Self {
let global = global.and_then(ExcludeNewerOverride::into_value);
let package: ExcludeNewerPackage = package.into_iter().collect();

Self { global, package }
Expand Down
5 changes: 3 additions & 2 deletions crates/uv-settings/src/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ use uv_pypi_types::{SchemaConflicts, SupportedEnvironments};
use uv_python::{PythonDownloads, PythonPreference, PythonVersion};
use uv_redacted::DisplaySafeUrl;
use uv_resolver::{
AnnotationStyle, ExcludeNewer, ExcludeNewerPackage, ExcludeNewerValue, ForkStrategy,
PrereleaseMode, ResolutionMode,
AnnotationStyle, ExcludeNewer, ExcludeNewerOverride, ExcludeNewerPackage, ExcludeNewerValue,
ForkStrategy, PrereleaseMode, ResolutionMode,
};
use uv_torch::TorchMode;
use uv_workspace::pyproject::ExtraBuildDependencies;
Expand Down Expand Up @@ -94,6 +94,7 @@ macro_rules! impl_combine_or {
impl_combine_or!(AddBoundsKind);
impl_combine_or!(AnnotationStyle);
impl_combine_or!(ExcludeNewer);
impl_combine_or!(ExcludeNewerOverride);
impl_combine_or!(ExcludeNewerValue);
impl_combine_or!(ExportFormat);
impl_combine_or!(ForkStrategy);
Expand Down
Loading
Loading