Skip to content

Commit d30f84c

Browse files
refactor: Move diff into a separate pixi_diff crate (#4697)
1 parent 591a17d commit d30f84c

File tree

12 files changed

+74
-24
lines changed

12 files changed

+74
-24
lines changed

Cargo.lock

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ pixi_config = { path = "crates/pixi_config" }
187187
pixi_consts = { path = "crates/pixi_consts" }
188188
pixi_core = { path = "crates/pixi_core" }
189189
pixi_default_versions = { path = "crates/pixi_default_versions" }
190+
pixi_diff = { path = "crates/pixi_diff" }
190191
pixi_git = { path = "crates/pixi_git" }
191192
pixi_glob = { path = "crates/pixi_glob" }
192193
pixi_global = { path = "crates/pixi_global" }

crates/pixi_cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ pixi_command_dispatcher = { workspace = true }
6969
pixi_config = { workspace = true }
7070
pixi_consts = { workspace = true }
7171
pixi_core = { workspace = true }
72+
pixi_diff = { workspace = true }
7273
pixi_git = { workspace = true }
7374
pixi_global = { workspace = true }
7475
pixi_manifest = { workspace = true, features = ["rattler_lock"] }

crates/pixi_cli/src/lock.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ use clap::Parser;
22
use miette::{Context, IntoDiagnostic};
33
use pixi_core::{
44
WorkspaceLocator,
5-
diff::{LockFileDiff, LockFileJsonDiff},
65
environment::LockFileUsage,
76
lock_file::{LockFileDerivedData, UpdateLockFileOptions},
87
};
8+
use pixi_diff::{LockFileDiff, LockFileJsonDiff};
99

1010
use crate::cli_config::NoInstallConfig;
11-
1211
use crate::cli_config::WorkspaceConfig;
1312

1413
/// Solve environment and update the lock file without installing the
@@ -54,7 +53,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
5453
// Format as json?
5554
if args.json {
5655
let diff = LockFileDiff::from_lock_files(&original_lock_file, &lock_file);
57-
let json_diff = LockFileJsonDiff::new(Some(&workspace), diff);
56+
let json_diff = LockFileJsonDiff::new(Some(workspace.named_environments()), diff);
5857
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
5958
println!("{}", json);
6059
} else if lock_updated {

crates/pixi_cli/src/update.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ use itertools::Itertools;
66
use miette::{Context, IntoDiagnostic, MietteDiagnostic};
77
use pixi_config::ConfigCli;
88
use pixi_consts::consts;
9+
use pixi_core::WorkspaceLocator;
910
use pixi_core::{
1011
Workspace,
1112
lock_file::{UpdateContext, filter_lock_file},
1213
};
13-
use pixi_core::{
14-
WorkspaceLocator,
15-
diff::{LockFileDiff, LockFileJsonDiff},
16-
};
14+
use pixi_diff::{LockFileDiff, LockFileJsonDiff};
1715
use pixi_manifest::EnvironmentName;
1816
use rattler_conda_types::Platform;
1917
use rattler_lock::{LockFile, LockedPackageRef};
@@ -182,7 +180,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
182180
// Format as json?
183181
if args.json {
184182
let diff = LockFileDiff::from_lock_files(loaded_lock_file, &lock_file);
185-
let json_diff = LockFileJsonDiff::new(Some(&workspace), diff);
183+
let json_diff = LockFileJsonDiff::new(Some(workspace.named_environments()), diff);
186184
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
187185
println!("{}", json);
188186
} else if diff.is_empty() {

crates/pixi_cli/src/upgrade.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use pep508_rs::{MarkerTree, Requirement};
99
use pixi_config::ConfigCli;
1010
use pixi_core::{
1111
WorkspaceLocator,
12-
diff::{LockFileDiff, LockFileJsonDiff},
1312
lock_file::UpdateContext,
1413
workspace::{MatchSpecs, PypiDeps, WorkspaceMut},
1514
};
15+
use pixi_diff::{LockFileDiff, LockFileJsonDiff};
1616
use pixi_manifest::{FeatureName, SpecType};
1717
use pixi_pypi_spec::PixiPypiSpec;
1818
use pixi_spec::PixiSpec;
@@ -223,7 +223,8 @@ pub async fn execute(args: Args) -> miette::Result<()> {
223223
.update()
224224
.await?;
225225
let diff = LockFileDiff::from_lock_files(&original_lock_file, &derived.lock_file);
226-
let json_diff = LockFileJsonDiff::new(Some(workspace.workspace()), diff);
226+
let json_diff =
227+
LockFileJsonDiff::new(Some(workspace.workspace().named_environments()), diff);
227228
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
228229
println!("{}", json);
229230
// Revert changes after computing the diff in dry-run mode.
@@ -233,7 +234,7 @@ pub async fn execute(args: Args) -> miette::Result<()> {
233234
let saved_workspace = workspace.save().await.into_diagnostic()?;
234235
let updated_lock_file = saved_workspace.load_lock_file().await?;
235236
let diff = LockFileDiff::from_lock_files(&original_lock_file, &updated_lock_file);
236-
let json_diff = LockFileJsonDiff::new(Some(&saved_workspace), diff);
237+
let json_diff = LockFileJsonDiff::new(Some(saved_workspace.named_environments()), diff);
237238
let json = serde_json::to_string_pretty(&json_diff).expect("failed to convert to json");
238239
println!("{}", json);
239240
}

crates/pixi_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ version = "0.1.0"
1212
slow_integration_tests = []
1313

1414
[dependencies]
15-
ahash = { workspace = true }
1615
async-once-cell = { workspace = true }
1716
barrier_cell = { workspace = true }
1817
chrono = { workspace = true }
@@ -40,6 +39,7 @@ pixi_command_dispatcher = { workspace = true }
4039
pixi_config = { workspace = true }
4140
pixi_consts = { workspace = true }
4241
pixi_default_versions = { workspace = true }
42+
pixi_diff = { workspace = true }
4343
pixi_git = { workspace = true }
4444
pixi_glob = { workspace = true }
4545
pixi_install_pypi = { workspace = true }

crates/pixi_core/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![deny(clippy::dbg_macro, clippy::unwrap_used)]
22

33
pub mod activation;
4-
pub mod diff;
54
pub mod environment;
65
pub mod lock_file;
76
pub mod prompt;

crates/pixi_core/src/workspace/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use std::{
2222

2323
use crate::{
2424
activation::{CurrentEnvVarBehavior, initialize_env_variables},
25-
diff::LockFileDiff,
2625
lock_file::filter_lock_file,
2726
repodata::Repodata,
2827
};
@@ -39,6 +38,7 @@ use pixi_build_frontend::BackendOverride;
3938
use pixi_command_dispatcher::{CacheDirs, CommandDispatcher, CommandDispatcherBuilder, Limits};
4039
use pixi_config::{Config, RunPostLinkScripts};
4140
use pixi_consts::consts;
41+
use pixi_diff::LockFileDiff;
4242
use pixi_manifest::{
4343
AssociateProvenance, BuildVariantSource, EnvironmentName, Environments, ExplicitManifestError,
4444
HasWorkspaceManifest, LoadManifestsError, ManifestProvenance, Manifests, PackageManifest,
@@ -441,6 +441,14 @@ impl Workspace {
441441
.collect()
442442
}
443443

444+
/// Returns a HashMap of environments in this project.
445+
pub fn named_environments(&self) -> HashMap<EnvironmentName, Environment> {
446+
self.environments()
447+
.iter()
448+
.map(|env| (env.name().clone(), env.clone()))
449+
.collect()
450+
}
451+
444452
/// Returns an environment in this project based on a name or an environment
445453
/// variable.
446454
pub fn environment_from_name_or_env_var(

crates/pixi_core/src/workspace/workspace_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use pixi_command_dispatcher::{
1515
CommandDispatcherError, MissingChannelError, SolvePixiEnvironmentError::MissingChannel,
1616
};
1717
use pixi_config::PinningStrategy;
18+
use pixi_diff::LockFileDiff;
1819
use pixi_manifest::{
1920
DependencyOverwriteBehavior, FeatureName, FeaturesExt, HasFeaturesIter, LoadManifestsError,
2021
ManifestDocument, ManifestKind, PypiDependencyLocation, SpecType, TomlError, WorkspaceManifest,
@@ -28,7 +29,6 @@ use toml_edit::DocumentMut;
2829

2930
use crate::{
3031
Workspace,
31-
diff::LockFileDiff,
3232
environment::LockFileUsage,
3333
lock_file::{LockFileDerivedData, ReinstallPackages, UpdateContext, UpdateMode},
3434
workspace::{

0 commit comments

Comments
 (0)