diff --git a/crates/pixi/tests/integration_rust/pypi_tests.rs b/crates/pixi/tests/integration_rust/pypi_tests.rs index 1f2c2c6173..d77eb8657f 100644 --- a/crates/pixi/tests/integration_rust/pypi_tests.rs +++ b/crates/pixi/tests/integration_rust/pypi_tests.rs @@ -1342,6 +1342,145 @@ async fn test_exclude_newer_relative_pypi_rejects_unknown_timestamps() { ); } +/// An exempted PyPI package is not subject to any cutoff, so releases without +/// an upload time are kept as well. Indexes such as Artifactory mirrors do not +/// report upload times at all. +#[tokio::test] +async fn test_exclude_newer_pypi_exemption_keeps_unknown_timestamps() { + setup_tracing(); + + let platform = Subdir::current().unwrap_or(Subdir::NoArch); + + let mut package_db = MockRepoData::default(); + package_db.add_package( + Package::build("python", "3.12.0") + .with_subdir(platform) + .with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()) + .finish(), + ); + let channel = package_db.into_channel().await.unwrap(); + + let pypi_index = PyPIDatabase::new() + .with(PyPIPackage::new("boltons", "20.2.1")) + .with( + PyPIPackage::new("bar", "1.0.0") + .with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()), + ) + .with( + PyPIPackage::new("bar", "2.0.0") + .with_timestamp("2020-12-02T07:00:00Z".parse().unwrap()), + ) + .into_simple_index() + .unwrap(); + + let pixi = PixiControl::from_manifest(&format!( + r#" + [workspace] + name = "test-exclude-newer-pypi-exemption-unknown-timestamps" + platforms = ["{platform}"] + channels = ["{channel_url}"] + exclude-newer = "2015-12-02T02:07:43Z" + pypi-exclude-newer = {{ exemptions = {{ boltons = "*" }} }} + conda-pypi-map = false + + [dependencies] + python = "==3.12.0" + + [pypi-dependencies] + boltons = "*" + bar = "*" + + [pypi-options] + index-url = "{pypi_index_url}" + "#, + platform = platform, + channel_url = channel.url(), + pypi_index_url = pypi_index.index_url(), + )) + .unwrap(); + + let lock_file = pixi.update_lock_file().await.unwrap(); + assert_eq!( + lock_file.get_pypi_package_version("default", platform, "boltons"), + Some("20.2.1".into()) + ); + // The cutoff still applies to the packages that are not exempted. + assert_eq!( + lock_file.get_pypi_package_version("default", platform, "bar"), + Some("1.0.0".into()) + ); +} + +/// A zero per-package cutoff in the deprecated `[pypi-exclude-newer]` table is +/// an exemption, so releases without an upload time are kept as well. +/// +/// Regression test for https://github.com/prefix-dev/pixi/issues/6159 +#[tokio::test] +async fn test_exclude_newer_pypi_zero_package_cutoff_keeps_unknown_timestamps() { + setup_tracing(); + + let platform = Subdir::current().unwrap_or(Subdir::NoArch); + + let mut package_db = MockRepoData::default(); + package_db.add_package( + Package::build("python", "3.12.0") + .with_subdir(platform) + .with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()) + .finish(), + ); + let channel = package_db.into_channel().await.unwrap(); + + let pypi_index = PyPIDatabase::new() + .with(PyPIPackage::new("boltons", "20.2.1")) + .with( + PyPIPackage::new("bar", "1.0.0") + .with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()), + ) + .with(PyPIPackage::new("bar", "2.0.0")) + .into_simple_index() + .unwrap(); + + let pixi = PixiControl::from_manifest(&format!( + r#" + [workspace] + name = "test-exclude-newer-pypi-zero-package-cutoff-unknown-timestamps" + platforms = ["{platform}"] + channels = ["{channel_url}"] + exclude-newer = "2015-12-02T02:07:43Z" + conda-pypi-map = false + + [pypi-exclude-newer] + boltons = "0d" + bar = "2100-01-01" + + [dependencies] + python = "==3.12.0" + + [pypi-dependencies] + boltons = "*" + bar = "*" + + [pypi-options] + index-url = "{pypi_index_url}" + "#, + platform = platform, + channel_url = channel.url(), + pypi_index_url = pypi_index.index_url(), + )) + .unwrap(); + + let lock_file = pixi.update_lock_file().await.unwrap(); + assert_eq!( + lock_file.get_pypi_package_version("default", platform, "boltons"), + Some("20.2.1".into()) + ); + // A non-zero cutoff still excludes releases without an upload time. + assert_eq!( + lock_file.get_pypi_package_version("default", platform, "bar"), + Some("1.0.0".into()) + ); +} + #[tokio::test] #[cfg_attr(not(feature = "online_tests"), ignore)] async fn test_allow_insecure_host() { diff --git a/crates/pixi_manifest/src/exclude_newer.rs b/crates/pixi_manifest/src/exclude_newer.rs index b7e48daa7a..001307c6ed 100644 --- a/crates/pixi_manifest/src/exclude_newer.rs +++ b/crates/pixi_manifest/src/exclude_newer.rs @@ -401,10 +401,18 @@ pub fn resolve_pypi_exclude_newer<'a>( .map(|cutoff| ResolvedPypiExcludeNewer::from_datetime(cutoff.cutoff())) .unwrap_or_default(); - #[allow(deprecated)] for (name, package_exclude_newer) in package_overrides { - exclude_newer = exclude_newer - .with_package_cutoff(name.as_normalized().clone(), package_exclude_newer.cutoff()); + // A zero cutoff such as `0d` lifts the cutoff for the package, which + // is what an exemption does. As an exemption, it also keeps releases + // without an upload time, which a cutoff of now would exclude. + exclude_newer = if matches!(package_exclude_newer, ExcludeNewer::Duration(d) if d.is_zero()) + { + 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()) + }; } for (name, version) in &config.exemptions { @@ -720,4 +728,33 @@ mod tests { // Without a cutoff nothing is excluded, so nothing is stale. assert_eq!(stale(&config, &[]), Vec::::new()); } + + #[test] + fn test_resolve_pypi_zero_package_cutoff_is_exemption() { + let config = PypiExcludeNewerConfig { + cutoff: Some(ExcludeNewer::from_str("2026-10-20T00:00:00Z").unwrap()), + exemptions: IndexMap::new(), + }; + let zero: PypiPackageName = "zero".parse().unwrap(); + let dated: PypiPackageName = "dated".parse().unwrap(); + let overrides = [ + (zero.clone(), ExcludeNewer::from_str("0d").unwrap()), + ( + dated.clone(), + ExcludeNewer::from_str("2026-10-25T00:00:00Z").unwrap(), + ), + ]; + + let resolved = + resolve_pypi_exclude_newer(&config, None, overrides.iter().map(|(n, c)| (n, c))); + + assert_eq!( + resolved.exempt_packages.iter().collect::>(), + [zero.as_normalized()] + ); + assert_eq!( + resolved.package_cutoffs.keys().collect::>(), + [dated.as_normalized()] + ); + } } diff --git a/docs/reference/pixi_manifest.md b/docs/reference/pixi_manifest.md index e37d95f57b..f56b04c569 100644 --- a/docs/reference/pixi_manifest.md +++ b/docs/reference/pixi_manifest.md @@ -503,7 +503,7 @@ torch = { version = ">=2.10.0", index = "https://download.pytorch.org/whl/cu124" !!! note Note that for PyPI package indexes the package index must support the `upload-time` field as specified in [`PEP 700`](https://peps.python.org/pep-0700/). - If the field is not present for a given distribution, the distribution will be treated as unavailable. PyPI provides `upload-time` for all packages. + If the field is not present for a given distribution, the distribution will be treated as unavailable, unless its package is exempted. PyPI provides `upload-time` for all packages. ### `build-variants` (optional)