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
81 changes: 81 additions & 0 deletions crates/pixi/tests/integration_rust/install_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1817,6 +1817,87 @@ async fn test_exclude_newer_per_package_constraint_override() {
));
}

#[tokio::test]
async fn test_exclude_newer_exemption_allows_vetted_release() {
setup_tracing();

let mut package_database = MockRepoData::default();
package_database.add_package(
Package::build("foo", "1")
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap())
.finish(),
);
package_database.add_package(
Package::build("foo", "2")
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap())
.finish(),
);
package_database.add_package(
Package::build("foo", "3")
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap())
.finish(),
);

// Only the vetted release `foo 2` is exempt from the cutoff, so the even
// newer `foo 3` stays excluded.
let channel = package_database.into_channel().await.unwrap();
let pixi = PixiControl::from_manifest(&format!(
r#"
[workspace]
name = "test-exclude-newer-exemption"
channels = ["{channel}"]
platforms = ["{platform}"]

[workspace.exclude-newer]
cutoff = "2015-12-02T02:07:43Z"
exemptions = {{ foo = "2" }}

[dependencies]
foo = "*"
"#,
channel = channel.url(),
platform = Subdir::current().unwrap_or(Subdir::NoArch)
))
.unwrap();

pixi.lock().await.unwrap();

let lock = pixi.lock_file().await.unwrap();
assert!(lock.contains_match_spec(
consts::DEFAULT_ENVIRONMENT_NAME,
Subdir::current().unwrap_or(Subdir::NoArch),
"foo ==2"
));

// A wildcard exemption lets every release of the package through. The
// locked `foo 2` stays valid under the wider exemption, so a fresh
// workspace is needed to observe the new pick.
let pixi = PixiControl::from_manifest(&format!(
r#"
[workspace]
name = "test-exclude-newer-wildcard-exemption"
channels = ["{channel}"]
platforms = ["{platform}"]
exclude-newer = {{ cutoff = "2015-12-02T02:07:43Z", exemptions = {{ foo = "*" }} }}

[dependencies]
foo = "*"
"#,
channel = channel.url(),
platform = Subdir::current().unwrap_or(Subdir::NoArch)
))
.unwrap();

pixi.lock().await.unwrap();

let lock = pixi.lock_file().await.unwrap();
assert!(lock.contains_match_spec(
consts::DEFAULT_ENVIRONMENT_NAME,
Subdir::current().unwrap_or(Subdir::NoArch),
"foo ==3"
));
}

#[tokio::test]
#[cfg_attr(
any(not(feature = "online_tests"), not(feature = "slow_integration_tests")),
Expand Down
105 changes: 105 additions & 0 deletions crates/pixi/tests/integration_rust/pypi_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,111 @@ async fn test_exclude_newer_per_package_pypi_index_override() {
);
}

#[tokio::test]
async fn test_exclude_newer_pypi_exemption_lifts_cutoff() {
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 idx = PyPIDatabase::new()
.with(
PyPIPackage::new("foo", "1.0.0")
.with_timestamp("2010-12-02T02:07:43Z".parse().unwrap()),
)
.with(
PyPIPackage::new("foo", "2.0.0")
.with_timestamp("2020-12-02T07:00:00Z".parse().unwrap()),
)
.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();

// The cutoff of `exclude-newer` applies to PyPI packages as well, but the
// exemption lifts it for `foo` alone.
let pixi = PixiControl::from_manifest(&format!(
r#"
[workspace]
name = "pypi-exclude-newer-exemption"
platforms = ["{platform}"]
channels = ["{channel_url}"]
exclude-newer = "2015-12-02T02:07:43Z"
pypi-exclude-newer = {{ exemptions = {{ foo = "*" }} }}
conda-pypi-map = false

[dependencies]
python = "==3.12.0"

[pypi-dependencies]
foo = "*"
bar = "*"

[pypi-options]
index-url = "{idx_url}"
"#,
platform = platform,
channel_url = channel.url(),
idx_url = idx.index_url(),
))
.unwrap();

let lock_file = pixi.update_lock_file().await.unwrap();
assert_eq!(
lock_file.get_pypi_package_version("default", platform, "foo"),
Some("2.0.0".into())
);
assert_eq!(
lock_file.get_pypi_package_version("default", platform, "bar"),
Some("1.0.0".into())
);

// A PyPI-specific cutoff applies without a conda cutoff.
let pixi = PixiControl::from_manifest(&format!(
r#"
[workspace]
name = "pypi-exclude-newer-own-cutoff"
platforms = ["{platform}"]
channels = ["{channel_url}"]
pypi-exclude-newer = "2015-12-02T02:07:43Z"
conda-pypi-map = false

[dependencies]
python = "==3.12.0"

[pypi-dependencies]
bar = "*"

[pypi-options]
index-url = "{idx_url}"
"#,
platform = platform,
channel_url = channel.url(),
idx_url = idx.index_url(),
))
.unwrap();

let lock_file = pixi.update_lock_file().await.unwrap();
assert_eq!(
lock_file.get_pypi_package_version("default", platform, "bar"),
Some("1.0.0".into())
);
}

#[tokio::test]
async fn test_exclude_newer_dependency_override_pypi_index_override() {
setup_tracing();
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_core/src/lock_file/outdated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ async fn find_unsatisfiable_targets<'p>(
}
EnvironmentUnsat::ChannelsMismatch
| EnvironmentUnsat::InvalidChannel(_)
| EnvironmentUnsat::ExcludeNewer(_)
| EnvironmentUnsat::ChannelPriorityMismatch { .. }
| EnvironmentUnsat::SolveStrategyMismatch { .. }
| EnvironmentUnsat::ExcludeNewerMismatch(..)
Expand Down
6 changes: 5 additions & 1 deletion crates/pixi_core/src/lock_file/satisfiability/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use itertools::Itertools;
use miette::Diagnostic;
use pep440_rs::VersionSpecifiers;
use pixi_command_dispatcher::{DevSourceMetadataError, SourceCheckoutError, SourceRecordError};
use pixi_manifest::{PixiPlatformName, pypi::pypi_options::PrereleaseMode};
use pixi_manifest::{ExcludeNewerError, PixiPlatformName, pypi::pypi_options::PrereleaseMode};
use pixi_record::{ParseLockFileError, SourceMismatchError};
use pixi_uv_conversions::AsPep508Error;
use rattler_conda_types::{MatchSpec, PackageName, ParseChannelError, ParseMatchSpecError};
Expand Down Expand Up @@ -42,6 +42,10 @@ pub enum EnvironmentUnsat {
#[error(transparent)]
InvalidChannel(#[from] ParseChannelError),

#[error(transparent)]
#[diagnostic(transparent)]
ExcludeNewer(#[from] ExcludeNewerError),

#[error(transparent)]
InvalidDistExtensionInNoBuild(#[from] ExtensionError),

Expand Down
14 changes: 12 additions & 2 deletions crates/pixi_core/src/lock_file/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ use pixi_install_pypi::{
PyPIEnvironmentUpdater, PyPIUpdateConfig, derive_link_mode,
};
use pixi_manifest::{
ChannelPriority, EnvironmentName, FeaturesExt, HasWorkspaceManifest, PixiPlatform,
PixiPlatformName,
ChannelPriority, EnvironmentName, ExcludeNewerError, FeaturesExt, HasWorkspaceManifest,
PixiPlatform, PixiPlatformName,
};
use pixi_progress::global_multi_progress;
use pixi_record::{LockFileResolver, ParseLockFileError, PixiRecord, UnresolvedPixiRecord};
Expand Down Expand Up @@ -604,6 +604,10 @@ pub enum SolveCondaEnvironmentError {
#[error(transparent)]
ParseChannels(#[from] Box<ParseChannelError>),

#[error(transparent)]
#[diagnostic(transparent)]
ExcludeNewer(#[from] Box<ExcludeNewerError>),

#[error(transparent)]
#[diagnostic(transparent)]
Variants(#[from] VariantsError),
Expand All @@ -620,6 +624,12 @@ impl From<ParseChannelError> for SolveCondaEnvironmentError {
}
}

impl From<ExcludeNewerError> for SolveCondaEnvironmentError {
fn from(value: ExcludeNewerError) -> Self {
SolveCondaEnvironmentError::ExcludeNewer(Box::new(value))
}
}

/// Options to pass to [`Workspace::update_lock_file`].
#[derive(Default)]
pub struct UpdateLockFileOptions {
Expand Down
62 changes: 62 additions & 0 deletions crates/pixi_core/src/workspace/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ mod tests {
use insta::assert_snapshot;
use itertools::Itertools;
use pixi_manifest::CondaDependencies;
use pixi_test_utils::uploaded_record;
use rattler_conda_types::{NamedChannelOrUrl, PackageName};

use super::*;
Expand Down Expand Up @@ -1271,6 +1272,67 @@ mod tests {
);
}

#[test]
fn test_exclude_newer_exemptions_win_over_channel_and_workspace_cutoffs() {
let workspace = Workspace::from_str(
Path::new("pixi.toml"),
r#"
[workspace]
name = "test"
channels = [{ channel = "my-private-forge", exclude-newer = "2016-12-02T02:07:43Z" }, "conda-forge"]
platforms = ["linux-64"]

[workspace.exclude-newer]
cutoff = "2015-12-02T02:07:43Z"
exemptions = { polars = "1.43.1", openssl = { version = "*", channel = "conda-forge" } }

[dependencies]
polars = "*"
openssl = "*"
"#,
)
.unwrap();

let channel_config = ChannelConfig::default_with_root_dir(std::env::current_dir().unwrap());
let env = workspace.environment("default").unwrap();
let config: rattler_solve::ExcludeNewer = env
.exclude_newer_config_resolved(&channel_config)
.unwrap()
.unwrap()
.into();

let my_private_forge = NamedChannelOrUrl::Name("my-private-forge".to_string())
.into_base_url(&channel_config)
.unwrap();
let conda_forge = NamedChannelOrUrl::Name("conda-forge".to_string())
.into_base_url(&channel_config)
.unwrap();

// The exempt release is allowed from any channel, other releases are
// not.
assert!(!config.is_excluded(&uploaded_record("polars", "1.43.1", Some(&conda_forge))));
assert!(!config.is_excluded(&uploaded_record(
"polars",
"1.43.1",
Some(&my_private_forge)
)));
assert!(config.is_excluded(&uploaded_record("polars", "1.43.2", Some(&conda_forge))));
assert!(config.is_excluded(&uploaded_record(
"polars",
"1.43.2",
Some(&my_private_forge)
)));

// An exemption with a channel only applies to records from that
// channel.
assert!(!config.is_excluded(&uploaded_record("openssl", "3.5.1", Some(&conda_forge))));
assert!(config.is_excluded(&uploaded_record(
"openssl",
"3.5.1",
Some(&my_private_forge)
)));
}

#[test]
fn test_exclude_newer_package_channel_workspace_precedence() {
let workspace = Workspace::from_str(
Expand Down
Loading
Loading