Skip to content

Commit db6d70d

Browse files
committed
feat(manifest): read exemptions from exclude-newer in [workspace]
`exclude-newer` keeps accepting a bare cutoff string, and now also takes a table with a `cutoff` and `exemptions`: [workspace.exclude-newer] cutoff = "7d" exemptions = { py-rattler = "*", polars = "1.43.1" } Exemptions are match specs, so a single vetted release can be allowed through without lowering the cutoff for every future release of the package. `pypi-exclude-newer` is added to `[workspace]` with the same shape. Its `cutoff` is optional and falls back to the conda cutoff. Exemptions only support `"*"` for now because uv can only lift the cutoff per package.
1 parent 7accc82 commit db6d70d

27 files changed

Lines changed: 2049 additions & 131 deletions

‎crates/pixi/tests/integration_rust/install_tests.rs‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,87 @@ async fn test_exclude_newer_per_package_constraint_override() {
18171817
));
18181818
}
18191819

1820+
#[tokio::test]
1821+
async fn test_exclude_newer_exemption_allows_vetted_release() {
1822+
setup_tracing();
1823+
1824+
let mut package_database = MockRepoData::default();
1825+
package_database.add_package(
1826+
Package::build("foo", "1")
1827+
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap())
1828+
.finish(),
1829+
);
1830+
package_database.add_package(
1831+
Package::build("foo", "2")
1832+
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap())
1833+
.finish(),
1834+
);
1835+
package_database.add_package(
1836+
Package::build("foo", "3")
1837+
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap())
1838+
.finish(),
1839+
);
1840+
1841+
// Only the vetted release `foo 2` is exempt from the cutoff, so the even
1842+
// newer `foo 3` stays excluded.
1843+
let channel = package_database.into_channel().await.unwrap();
1844+
let pixi = PixiControl::from_manifest(&format!(
1845+
r#"
1846+
[workspace]
1847+
name = "test-exclude-newer-exemption"
1848+
channels = ["{channel}"]
1849+
platforms = ["{platform}"]
1850+
1851+
[workspace.exclude-newer]
1852+
cutoff = "2015-12-02T02:07:43Z"
1853+
exemptions = {{ foo = "2" }}
1854+
1855+
[dependencies]
1856+
foo = "*"
1857+
"#,
1858+
channel = channel.url(),
1859+
platform = Subdir::current().unwrap_or(Subdir::NoArch)
1860+
))
1861+
.unwrap();
1862+
1863+
pixi.lock().await.unwrap();
1864+
1865+
let lock = pixi.lock_file().await.unwrap();
1866+
assert!(lock.contains_match_spec(
1867+
consts::DEFAULT_ENVIRONMENT_NAME,
1868+
Subdir::current().unwrap_or(Subdir::NoArch),
1869+
"foo ==2"
1870+
));
1871+
1872+
// A wildcard exemption lets every release of the package through. The
1873+
// locked `foo 2` stays valid under the wider exemption, so a fresh
1874+
// workspace is needed to observe the new pick.
1875+
let pixi = PixiControl::from_manifest(&format!(
1876+
r#"
1877+
[workspace]
1878+
name = "test-exclude-newer-wildcard-exemption"
1879+
channels = ["{channel}"]
1880+
platforms = ["{platform}"]
1881+
exclude-newer = {{ cutoff = "2015-12-02T02:07:43Z", exemptions = {{ foo = "*" }} }}
1882+
1883+
[dependencies]
1884+
foo = "*"
1885+
"#,
1886+
channel = channel.url(),
1887+
platform = Subdir::current().unwrap_or(Subdir::NoArch)
1888+
))
1889+
.unwrap();
1890+
1891+
pixi.lock().await.unwrap();
1892+
1893+
let lock = pixi.lock_file().await.unwrap();
1894+
assert!(lock.contains_match_spec(
1895+
consts::DEFAULT_ENVIRONMENT_NAME,
1896+
Subdir::current().unwrap_or(Subdir::NoArch),
1897+
"foo ==3"
1898+
));
1899+
}
1900+
18201901
#[tokio::test]
18211902
#[cfg_attr(
18221903
any(not(feature = "online_tests"), not(feature = "slow_integration_tests")),

‎crates/pixi/tests/integration_rust/pypi_tests.rs‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,111 @@ async fn test_exclude_newer_per_package_pypi_index_override() {
977977
);
978978
}
979979

980+
#[tokio::test]
981+
async fn test_exclude_newer_pypi_exemption_lifts_cutoff() {
982+
setup_tracing();
983+
984+
let platform = Subdir::current().unwrap_or(Subdir::NoArch);
985+
986+
let mut package_db = MockRepoData::default();
987+
package_db.add_package(
988+
Package::build("python", "3.12.0")
989+
.with_subdir(platform)
990+
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap())
991+
.finish(),
992+
);
993+
let channel = package_db.into_channel().await.unwrap();
994+
995+
let idx = PyPIDatabase::new()
996+
.with(
997+
PyPIPackage::new("foo", "1.0.0")
998+
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()),
999+
)
1000+
.with(
1001+
PyPIPackage::new("foo", "2.0.0")
1002+
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap()),
1003+
)
1004+
.with(
1005+
PyPIPackage::new("bar", "1.0.0")
1006+
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()),
1007+
)
1008+
.with(
1009+
PyPIPackage::new("bar", "2.0.0")
1010+
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap()),
1011+
)
1012+
.into_simple_index()
1013+
.unwrap();
1014+
1015+
// The cutoff of `exclude-newer` applies to PyPI packages as well, but the
1016+
// exemption lifts it for `foo` alone.
1017+
let pixi = PixiControl::from_manifest(&format!(
1018+
r#"
1019+
[workspace]
1020+
name = "pypi-exclude-newer-exemption"
1021+
platforms = ["{platform}"]
1022+
channels = ["{channel_url}"]
1023+
exclude-newer = "2015-12-02T02:07:43Z"
1024+
pypi-exclude-newer = {{ exemptions = {{ foo = "*" }} }}
1025+
conda-pypi-map = false
1026+
1027+
[dependencies]
1028+
python = "==3.12.0"
1029+
1030+
[pypi-dependencies]
1031+
foo = "*"
1032+
bar = "*"
1033+
1034+
[pypi-options]
1035+
index-url = "{idx_url}"
1036+
"#,
1037+
platform = platform,
1038+
channel_url = channel.url(),
1039+
idx_url = idx.index_url(),
1040+
))
1041+
.unwrap();
1042+
1043+
let lock_file = pixi.update_lock_file().await.unwrap();
1044+
assert_eq!(
1045+
lock_file.get_pypi_package_version("default", platform, "foo"),
1046+
Some("2.0.0".into())
1047+
);
1048+
assert_eq!(
1049+
lock_file.get_pypi_package_version("default", platform, "bar"),
1050+
Some("1.0.0".into())
1051+
);
1052+
1053+
// A PyPI-specific cutoff applies without a conda cutoff.
1054+
let pixi = PixiControl::from_manifest(&format!(
1055+
r#"
1056+
[workspace]
1057+
name = "pypi-exclude-newer-own-cutoff"
1058+
platforms = ["{platform}"]
1059+
channels = ["{channel_url}"]
1060+
pypi-exclude-newer = "2015-12-02T02:07:43Z"
1061+
conda-pypi-map = false
1062+
1063+
[dependencies]
1064+
python = "==3.12.0"
1065+
1066+
[pypi-dependencies]
1067+
bar = "*"
1068+
1069+
[pypi-options]
1070+
index-url = "{idx_url}"
1071+
"#,
1072+
platform = platform,
1073+
channel_url = channel.url(),
1074+
idx_url = idx.index_url(),
1075+
))
1076+
.unwrap();
1077+
1078+
let lock_file = pixi.update_lock_file().await.unwrap();
1079+
assert_eq!(
1080+
lock_file.get_pypi_package_version("default", platform, "bar"),
1081+
Some("1.0.0".into())
1082+
);
1083+
}
1084+
9801085
#[tokio::test]
9811086
async fn test_exclude_newer_dependency_override_pypi_index_override() {
9821087
setup_tracing();

‎crates/pixi_core/src/lock_file/outdated.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ async fn find_unsatisfiable_targets<'p>(
321321
}
322322
EnvironmentUnsat::ChannelsMismatch
323323
| EnvironmentUnsat::InvalidChannel(_)
324+
| EnvironmentUnsat::ExcludeNewer(_)
324325
| EnvironmentUnsat::ChannelPriorityMismatch { .. }
325326
| EnvironmentUnsat::SolveStrategyMismatch { .. }
326327
| EnvironmentUnsat::ExcludeNewerMismatch(..)

‎crates/pixi_core/src/lock_file/satisfiability/errors.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use itertools::Itertools;
88
use miette::Diagnostic;
99
use pep440_rs::VersionSpecifiers;
1010
use pixi_command_dispatcher::{DevSourceMetadataError, SourceCheckoutError, SourceRecordError};
11-
use pixi_manifest::{PixiPlatformName, pypi::pypi_options::PrereleaseMode};
11+
use pixi_manifest::{ExcludeNewerError, PixiPlatformName, pypi::pypi_options::PrereleaseMode};
1212
use pixi_record::{ParseLockFileError, SourceMismatchError};
1313
use pixi_uv_conversions::AsPep508Error;
1414
use rattler_conda_types::{MatchSpec, PackageName, ParseChannelError, ParseMatchSpecError};
@@ -42,6 +42,10 @@ pub enum EnvironmentUnsat {
4242
#[error(transparent)]
4343
InvalidChannel(#[from] ParseChannelError),
4444

45+
#[error(transparent)]
46+
#[diagnostic(transparent)]
47+
ExcludeNewer(#[from] ExcludeNewerError),
48+
4549
#[error(transparent)]
4650
InvalidDistExtensionInNoBuild(#[from] ExtensionError),
4751

‎crates/pixi_core/src/lock_file/update.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ use pixi_install_pypi::{
3636
PyPIUpdateConfig, derive_link_mode,
3737
};
3838
use pixi_manifest::{
39-
ChannelPriority, EnvironmentName, FeaturesExt, HasWorkspaceManifest, PixiPlatform,
40-
PixiPlatformName,
39+
ChannelPriority, EnvironmentName, ExcludeNewerError, FeaturesExt, HasWorkspaceManifest,
40+
PixiPlatform, PixiPlatformName,
4141
};
4242
use pixi_progress::global_multi_progress;
4343
use pixi_record::{LockFileResolver, ParseLockFileError, PixiRecord, UnresolvedPixiRecord};
@@ -604,6 +604,10 @@ pub enum SolveCondaEnvironmentError {
604604
#[error(transparent)]
605605
ParseChannels(#[from] Box<ParseChannelError>),
606606

607+
#[error(transparent)]
608+
#[diagnostic(transparent)]
609+
ExcludeNewer(#[from] Box<ExcludeNewerError>),
610+
607611
#[error(transparent)]
608612
#[diagnostic(transparent)]
609613
Variants(#[from] VariantsError),
@@ -620,6 +624,12 @@ impl From<ParseChannelError> for SolveCondaEnvironmentError {
620624
}
621625
}
622626

627+
impl From<ExcludeNewerError> for SolveCondaEnvironmentError {
628+
fn from(value: ExcludeNewerError) -> Self {
629+
SolveCondaEnvironmentError::ExcludeNewer(Box::new(value))
630+
}
631+
}
632+
623633
/// Options to pass to [`Workspace::update_lock_file`].
624634
#[derive(Default)]
625635
pub struct UpdateLockFileOptions {

‎crates/pixi_core/src/workspace/environment.rs‎

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -533,13 +533,13 @@ impl Hash for Environment<'_> {
533533

534534
#[cfg(test)]
535535
mod tests {
536-
use std::{collections::HashSet, path::Path};
536+
use std::{collections::HashSet, path::Path, str::FromStr};
537537

538538
use indexmap::indexmap;
539539
use insta::assert_snapshot;
540540
use itertools::Itertools;
541541
use pixi_manifest::CondaDependencies;
542-
use rattler_conda_types::{NamedChannelOrUrl, PackageName};
542+
use rattler_conda_types::{ChannelUrl, NamedChannelOrUrl, PackageName};
543543

544544
use super::*;
545545

@@ -1271,6 +1271,81 @@ mod tests {
12711271
);
12721272
}
12731273

1274+
#[test]
1275+
fn test_exclude_newer_exemptions_win_over_channel_and_workspace_cutoffs() {
1276+
let workspace = Workspace::from_str(
1277+
Path::new("pixi.toml"),
1278+
r#"
1279+
[workspace]
1280+
name = "test"
1281+
channels = [{ channel = "my-private-forge", exclude-newer = "2016-12-02T02:07:43Z" }, "conda-forge"]
1282+
platforms = ["linux-64"]
1283+
1284+
[workspace.exclude-newer]
1285+
cutoff = "2015-12-02T02:07:43Z"
1286+
exemptions = { polars = "1.43.1", openssl = { version = "*", channel = "conda-forge" } }
1287+
1288+
[dependencies]
1289+
polars = "*"
1290+
openssl = "*"
1291+
"#,
1292+
)
1293+
.unwrap();
1294+
1295+
let channel_config = ChannelConfig::default_with_root_dir(std::env::current_dir().unwrap());
1296+
let env = workspace.environment("default").unwrap();
1297+
let config: rattler_solve::ExcludeNewer = env
1298+
.exclude_newer_config_resolved(&channel_config)
1299+
.unwrap()
1300+
.unwrap()
1301+
.into();
1302+
1303+
let my_private_forge = NamedChannelOrUrl::Name("my-private-forge".to_string())
1304+
.into_base_url(&channel_config)
1305+
.unwrap();
1306+
let conda_forge = NamedChannelOrUrl::Name("conda-forge".to_string())
1307+
.into_base_url(&channel_config)
1308+
.unwrap();
1309+
1310+
let record = |name: &str, version: &str, channel: &ChannelUrl| {
1311+
let mut package_record = rattler_conda_types::PackageRecord::new(
1312+
PackageName::new_unchecked(name),
1313+
rattler_conda_types::Version::from_str(version).unwrap(),
1314+
"0".to_string(),
1315+
);
1316+
package_record.timestamp = Some(
1317+
"2020-01-01T00:00:00Z"
1318+
.parse::<jiff::Timestamp>()
1319+
.unwrap()
1320+
.into(),
1321+
);
1322+
rattler_conda_types::RepoDataRecord {
1323+
package_record,
1324+
identifier: rattler_conda_types::package::DistArchiveIdentifier::from_str(
1325+
&format!("{name}-{version}-0.conda"),
1326+
)
1327+
.unwrap(),
1328+
url: channel
1329+
.url()
1330+
.join(&format!("noarch/{name}-{version}-0.conda"))
1331+
.unwrap(),
1332+
channel: Some(channel.to_string()),
1333+
}
1334+
};
1335+
1336+
// The exempt release is allowed from any channel, other releases are
1337+
// not.
1338+
assert!(!config.is_excluded(&record("polars", "1.43.1", &conda_forge)));
1339+
assert!(!config.is_excluded(&record("polars", "1.43.1", &my_private_forge)));
1340+
assert!(config.is_excluded(&record("polars", "1.43.2", &conda_forge)));
1341+
assert!(config.is_excluded(&record("polars", "1.43.2", &my_private_forge)));
1342+
1343+
// An exemption with a channel only applies to records from that
1344+
// channel.
1345+
assert!(!config.is_excluded(&record("openssl", "3.5.1", &conda_forge)));
1346+
assert!(config.is_excluded(&record("openssl", "3.5.1", &my_private_forge)));
1347+
}
1348+
12741349
#[test]
12751350
fn test_exclude_newer_package_channel_workspace_precedence() {
12761351
let workspace = Workspace::from_str(

0 commit comments

Comments
 (0)