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
1 change: 1 addition & 0 deletions crates/pixi_global/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,7 @@ impl Project {
channels,
self.global_channel_config(),
std::iter::empty(),
chrono::Utc::now(),
)
}

Expand Down
43 changes: 17 additions & 26 deletions crates/pixi_manifest/src/exclude_newer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,12 @@ pub enum ExcludeNewerError {
///
/// `package_overrides` are the per-package cutoffs of the deprecated top-level
/// `[exclude-newer]` table. They keep working until that table is removed.
/// Relative cutoffs are resolved as if the current time were `now`.
pub fn resolve_exclude_newer<'a>(
config: &ExcludeNewerConfig,
channels: impl IntoIterator<Item = &'a PrioritizedChannel>,
channel_config: &ChannelConfig,
package_overrides: impl IntoIterator<Item = (&'a PackageName, &'a ExcludeNewer)>,
) -> Result<Option<ResolvedExcludeNewer>, ExcludeNewerError> {
resolve_exclude_newer_at(
config,
channels,
channel_config,
package_overrides,
Utc::now(),
)
}

/// Like [`resolve_exclude_newer`], with relative cutoffs resolved as if the
/// current time were `now`.
fn resolve_exclude_newer_at<'a>(
config: &ExcludeNewerConfig,
channels: impl IntoIterator<Item = &'a PrioritizedChannel>,
channel_config: &ChannelConfig,
package_overrides: impl IntoIterator<Item = (&'a PackageName, &'a ExcludeNewer)>,
now: DateTime<Utc>,
) -> Result<Option<ResolvedExcludeNewer>, ExcludeNewerError> {
let mut exclude_newer = config
Expand Down Expand Up @@ -351,7 +335,7 @@ where
let mut resolved = environments
.into_iter()
.map(|channels| {
resolve_exclude_newer_at(
resolve_exclude_newer(
config,
channels,
channel_config,
Expand All @@ -362,7 +346,7 @@ where
.collect::<Result<Vec<_>, _>>()?;
// Without environments, the exemptions apply to the ones added later.
if resolved.is_empty() {
resolved.push(resolve_exclude_newer_at(
resolved.push(resolve_exclude_newer(
config,
[],
channel_config,
Expand Down Expand Up @@ -400,16 +384,17 @@ where
///
/// `package_overrides` are the per-package cutoffs of the deprecated top-level
/// `[pypi-exclude-newer]` table. They keep working until that table is
/// removed.
/// removed. Relative cutoffs are resolved as if the current time were `now`.
pub fn resolve_pypi_exclude_newer<'a>(
config: &PypiExcludeNewerConfig,
fallback_cutoff: Option<ExcludeNewer>,
package_overrides: impl IntoIterator<Item = (&'a PypiPackageName, &'a ExcludeNewer)>,
now: DateTime<Utc>,
) -> ResolvedPypiExcludeNewer {
let mut exclude_newer = config
.cutoff
.or(fallback_cutoff)
.map(|cutoff| ResolvedPypiExcludeNewer::from_datetime(cutoff.cutoff()))
.map(|cutoff| ResolvedPypiExcludeNewer::from_datetime(cutoff.cutoff_at(now)))
.unwrap_or_default();

for (name, package_exclude_newer) in package_overrides {
Expand All @@ -421,8 +406,10 @@ pub fn resolve_pypi_exclude_newer<'a>(
exclude_newer.with_exempt_package(name.as_normalized().clone())
} else {
#[allow(deprecated)]
exclude_newer
.with_package_cutoff(name.as_normalized().clone(), package_exclude_newer.cutoff())
exclude_newer.with_package_cutoff(
name.as_normalized().clone(),
package_exclude_newer.cutoff_at(now),
)
};
}

Expand Down Expand Up @@ -755,7 +742,7 @@ mod tests {
};
let channels = [channel("conda-forge", Some("7d"))];
let configured_hash = |config: &ExcludeNewerConfig, now: &str| {
let resolved = resolve_exclude_newer_at(
let resolved = resolve_exclude_newer(
config,
&channels,
&ChannelConfig::default_with_root_dir("/".into()),
Expand Down Expand Up @@ -799,8 +786,12 @@ mod tests {
),
];

let resolved =
resolve_pypi_exclude_newer(&config, None, overrides.iter().map(|(n, c)| (n, c)));
let resolved = resolve_pypi_exclude_newer(
&config,
None,
overrides.iter().map(|(n, c)| (n, c)),
Utc::now(),
);

assert_eq!(
resolved.exempt_packages.iter().collect::<Vec<_>>(),
Expand Down
2 changes: 2 additions & 0 deletions crates/pixi_manifest/src/features_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub trait FeaturesExt<'source>: HasWorkspaceManifest<'source> + HasFeaturesIter<
self.prioritized_channels().into_values(),
channel_config,
&workspace.exclude_newer_package_overrides,
self.workspace_manifest().loaded_at,
)
}

Expand All @@ -128,6 +129,7 @@ pub trait FeaturesExt<'source>: HasWorkspaceManifest<'source> + HasFeaturesIter<
&workspace.pypi_exclude_newer,
workspace.exclude_newer.cutoff,
&workspace.pypi_exclude_newer_package_overrides,
self.workspace_manifest().loaded_at,
)
}

Expand Down
50 changes: 49 additions & 1 deletion crates/pixi_manifest/src/manifests/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
str::FromStr,
};

use chrono::{DateTime, Utc};
use indexmap::{Equivalent, IndexMap, IndexSet};
use itertools::Itertools;
use miette::SourceCode;
Expand Down Expand Up @@ -40,7 +41,7 @@ use crate::{

/// Holds the parsed content of the workspace part of a pixi manifest. This
/// describes the part related to the workspace only.
#[derive(Debug, Default, Clone)]
#[derive(Debug, Clone)]
pub struct WorkspaceManifest {
/// Information about the project
pub workspace: Workspace,
Expand All @@ -56,6 +57,22 @@ pub struct WorkspaceManifest {

/// The solve groups that are part of the project.
pub solve_groups: SolveGroups,

/// The time relative `exclude-newer` cutoffs are resolved against, fixed
/// at load so that every environment resolves them to the same time.
pub loaded_at: DateTime<Utc>,
}

impl Default for WorkspaceManifest {
fn default() -> Self {
Self {
workspace: Workspace::default(),
features: IndexMap::default(),
environments: Environments::default(),
solve_groups: SolveGroups::default(),
loaded_at: Utc::now(),
}
}
}

impl WorkspaceManifest {
Expand Down Expand Up @@ -6680,6 +6697,37 @@ exclude-newer = { cutoff = "2015-12-02T02:07:43Z", exemptions = { polars = "1.43
assert!(config.is_excluded(&uploaded_record("pandas", "2.0.0", None)));
}

/// Regression test. Every solve resolved a relative cutoff against its
/// own `Utc::now()`, so the compute keys carrying the resolved cutoff,
/// such as the build backend environment, were never deduplicated.
#[test]
fn test_relative_exclude_newer_resolves_against_load_time() {
let contents = r#"
[workspace]
name = "foo"
channels = []
platforms = []
exclude-newer = "14d"
"#;
let manifest = parse_pixi_toml(contents).manifest;
let features = DefaultFeature(&manifest);
let expected = manifest.loaded_at - chrono::Duration::days(14);

let resolve = || {
features
.exclude_newer_config_resolved(&default_channel_config())
.unwrap()
.unwrap()
};
let first = resolve();
assert_eq!(first.cutoff, expected);
assert_eq!(first, resolve());

let pypi = features.pypi_exclude_newer_config_resolved();
assert_eq!(pypi.cutoff, Some(expected));
assert_eq!(pypi, features.pypi_exclude_newer_config_resolved());
}

#[test]
fn test_pypi_exclude_newer_config_falls_back_to_conda_cutoff() {
let contents = r#"
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_manifest/src/toml/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ impl TomlManifest {
features,
environments,
solve_groups,
loaded_at: chrono::Utc::now(),
};
workspace_manifest.register_composed_platforms()?;

Expand Down
Loading