Skip to content
Open
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
20 changes: 19 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ pixi_config = { path = "crates/pixi_config" }
pixi_consts = { path = "crates/pixi_consts" }
pixi_core = { path = "crates/pixi_core" }
pixi_default_versions = { path = "crates/pixi_default_versions" }
pixi_diff = { path = "crates/pixi_diff" }
pixi_git = { path = "crates/pixi_git" }
pixi_glob = { path = "crates/pixi_glob" }
pixi_global = { path = "crates/pixi_global" }
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pixi_command_dispatcher = { workspace = true }
pixi_config = { workspace = true }
pixi_consts = { workspace = true }
pixi_core = { workspace = true }
pixi_diff = { workspace = true }
pixi_git = { workspace = true }
pixi_global = { workspace = true }
pixi_manifest = { workspace = true, features = ["rattler_lock"] }
Expand Down
5 changes: 2 additions & 3 deletions crates/pixi_cli/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use clap::Parser;
use miette::{Context, IntoDiagnostic};
use pixi_core::{
WorkspaceLocator,
diff::{LockFileDiff, LockFileJsonDiff},
environment::LockFileUsage,
lock_file::{LockFileDerivedData, UpdateLockFileOptions},
};
use pixi_diff::{LockFileDiff, LockFileJsonDiff};

use crate::cli_config::NoInstallConfig;

use crate::cli_config::WorkspaceConfig;

/// Solve environment and update the lock file without installing the
Expand Down Expand Up @@ -54,7 +53,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Format as json?
if args.json {
let diff = LockFileDiff::from_lock_files(&original_lock_file, &lock_file);
let json_diff = LockFileJsonDiff::new(Some(&workspace), diff);
let json_diff = LockFileJsonDiff::new(Some(workspace.named_environments()), diff);
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
println!("{}", json);
} else if lock_updated {
Expand Down
8 changes: 3 additions & 5 deletions crates/pixi_cli/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ use itertools::Itertools;
use miette::{Context, IntoDiagnostic, MietteDiagnostic};
use pixi_config::ConfigCli;
use pixi_consts::consts;
use pixi_core::WorkspaceLocator;
use pixi_core::{
Workspace,
lock_file::{UpdateContext, filter_lock_file},
};
use pixi_core::{
WorkspaceLocator,
diff::{LockFileDiff, LockFileJsonDiff},
};
use pixi_diff::{LockFileDiff, LockFileJsonDiff};
use pixi_manifest::EnvironmentName;
use rattler_conda_types::Platform;
use rattler_lock::{LockFile, LockedPackageRef};
Expand Down Expand Up @@ -182,7 +180,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
// Format as json?
if args.json {
let diff = LockFileDiff::from_lock_files(loaded_lock_file, &lock_file);
let json_diff = LockFileJsonDiff::new(Some(&workspace), diff);
let json_diff = LockFileJsonDiff::new(Some(workspace.named_environments()), diff);
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
println!("{}", json);
} else if diff.is_empty() {
Expand Down
7 changes: 4 additions & 3 deletions crates/pixi_cli/src/upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use pep508_rs::{MarkerTree, Requirement};
use pixi_config::ConfigCli;
use pixi_core::{
WorkspaceLocator,
diff::{LockFileDiff, LockFileJsonDiff},
lock_file::UpdateContext,
workspace::{MatchSpecs, PypiDeps, WorkspaceMut},
};
use pixi_diff::{LockFileDiff, LockFileJsonDiff};
use pixi_manifest::{FeatureName, SpecType};
use pixi_pypi_spec::PixiPypiSpec;
use pixi_spec::PixiSpec;
Expand Down Expand Up @@ -223,7 +223,8 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.update()
.await?;
let diff = LockFileDiff::from_lock_files(&original_lock_file, &derived.lock_file);
let json_diff = LockFileJsonDiff::new(Some(workspace.workspace()), diff);
let json_diff =
LockFileJsonDiff::new(Some(workspace.workspace().named_environments()), diff);
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
println!("{}", json);
// Revert changes after computing the diff in dry-run mode.
Expand All @@ -233,7 +234,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let saved_workspace = workspace.save().await.into_diagnostic()?;
let updated_lock_file = saved_workspace.load_lock_file().await?;
let diff = LockFileDiff::from_lock_files(&original_lock_file, &updated_lock_file);
let json_diff = LockFileJsonDiff::new(Some(&saved_workspace), diff);
let json_diff = LockFileJsonDiff::new(Some(saved_workspace.named_environments()), diff);
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
println!("{}", json);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ version = "0.1.0"
slow_integration_tests = []

[dependencies]
ahash = { workspace = true }
async-once-cell = { workspace = true }
barrier_cell = { workspace = true }
chrono = { workspace = true }
Expand Down Expand Up @@ -41,6 +40,7 @@ pixi_command_dispatcher = { workspace = true }
pixi_config = { workspace = true }
pixi_consts = { workspace = true }
pixi_default_versions = { workspace = true }
pixi_diff = { workspace = true }
pixi_git = { workspace = true }
pixi_glob = { workspace = true }
pixi_install_pypi = { workspace = true }
Expand Down
1 change: 0 additions & 1 deletion crates/pixi_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#![deny(clippy::dbg_macro, clippy::unwrap_used)]

pub mod activation;
pub mod diff;
pub mod environment;
pub mod lock_file;
pub mod prompt;
Expand Down
10 changes: 9 additions & 1 deletion crates/pixi_core/src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use std::{

use crate::{
activation::{CurrentEnvVarBehavior, initialize_env_variables},
diff::LockFileDiff,
lock_file::filter_lock_file,
repodata::Repodata,
};
Expand All @@ -38,6 +37,7 @@ use pixi_build_frontend::BackendOverride;
use pixi_command_dispatcher::{CacheDirs, CommandDispatcher, CommandDispatcherBuilder, Limits};
use pixi_config::{Config, RunPostLinkScripts};
use pixi_consts::consts;
use pixi_diff::LockFileDiff;
use pixi_manifest::{
AssociateProvenance, EnvironmentName, Environments, ExplicitManifestError,
HasWorkspaceManifest, LoadManifestsError, ManifestProvenance, Manifests, PackageManifest,
Expand Down Expand Up @@ -426,6 +426,14 @@ impl Workspace {
.collect()
}

/// Returns a HashMap of environments in this project.
pub fn named_environments(&self) -> HashMap<EnvironmentName, Environment> {
self.environments()
.iter()
.map(|env| (env.name().clone(), env.clone()))
.collect()
}

/// Returns an environment in this project based on a name or an environment
/// variable.
pub fn environment_from_name_or_env_var(
Expand Down
2 changes: 1 addition & 1 deletion crates/pixi_core/src/workspace/workspace_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use pixi_command_dispatcher::{
CommandDispatcherError, MissingChannelError, SolvePixiEnvironmentError::MissingChannel,
};
use pixi_config::PinningStrategy;
use pixi_diff::LockFileDiff;
use pixi_manifest::{
DependencyOverwriteBehavior, FeatureName, FeaturesExt, HasFeaturesIter, LoadManifestsError,
ManifestDocument, ManifestKind, PypiDependencyLocation, SpecType, TomlError, WorkspaceManifest,
Expand All @@ -28,7 +29,6 @@ use toml_edit::DocumentMut;

use crate::{
Workspace,
diff::LockFileDiff,
environment::LockFileUsage,
lock_file::{LockFileDerivedData, ReinstallPackages, UpdateContext, UpdateMode},
workspace::{
Expand Down
22 changes: 22 additions & 0 deletions crates/pixi_diff/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
name = "pixi_diff"
readme.workspace = true
repository.workspace = true
version = "0.1.0"

[dependencies]
ahash = { workspace = true }
console = { workspace = true }
indexmap = { workspace = true }
itertools = { workspace = true }
pixi_consts = { workspace = true }
pixi_manifest = { workspace = true }
rattler_conda_types = { workspace = true }
rattler_lock = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tabwriter = { workspace = true }
19 changes: 11 additions & 8 deletions crates/pixi_core/src/diff.rs → crates/pixi_diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ use ahash::HashMap;
use indexmap::IndexMap;
use itertools::{Either, Itertools};
use pixi_consts::consts;
use pixi_manifest::FeaturesExt;
use pixi_manifest::{EnvironmentName, FeaturesExt};
use rattler_conda_types::Platform;
use rattler_lock::{LockFile, LockedPackage, LockedPackageRef};
use serde::Serialize;
use serde_json::Value;
use tabwriter::TabWriter;

use crate::Workspace;

// Represents the differences between two sets of packages.
#[derive(Default, Clone)]
pub struct PackagesDiff {
Expand Down Expand Up @@ -377,24 +375,29 @@ pub struct LockFileJsonDiff {
}

impl LockFileJsonDiff {
pub fn new(project: Option<&Workspace>, value: LockFileDiff) -> Self {
pub fn new<'a, F: FeaturesExt<'a>>(
environments: Option<std::collections::HashMap<EnvironmentName, F>>,
value: LockFileDiff,
) -> Self {
let mut environment = IndexMap::new();

for (environment_name, environment_diff) in value.environment {
let mut environment_diff_json = IndexMap::new();

for (platform, packages_diff) in environment_diff {
let conda_dependencies = project
let conda_dependencies = environments
.as_ref()
.and_then(|p| {
p.environment(environment_name.as_str()).map(|env| {
p.get(environment_name.as_str()).map(|env| {
env.dependencies(pixi_manifest::SpecType::Run, Some(platform))
})
})
.unwrap_or_default();

let pypi_dependencies = project
let pypi_dependencies = environments
.as_ref()
.and_then(|p| {
p.environment(environment_name.as_str())
p.get(environment_name.as_str())
.map(|env| env.pypi_dependencies(Some(platform)))
})
.unwrap_or_default();
Expand Down
Loading