Skip to content
1 change: 1 addition & 0 deletions crates/pixi/tests/integration_rust/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ impl PixiControl {
no_install_config: NoInstallConfig { no_install: false },
check: false,
json: false,
dry_run: false,
},
}
}
Expand Down
28 changes: 26 additions & 2 deletions crates/pixi_cli/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ pub struct Args {
/// If yes, exit with a non-zero code.
#[clap(long)]
pub check: bool,

///Compute the lock file without writing to disk.
/// Implies --no-install
#[clap(long)]
pub dry_run: bool,
}

pub async fn execute(args: Args) -> miette::Result<()> {
Expand All @@ -47,8 +52,12 @@ pub async fn execute(args: Args) -> miette::Result<()> {
let original_lock_file = workspace.load_lock_file().await?.into_lock_file_or_empty();
let (LockFileDerivedData { lock_file, .. }, lock_updated) = workspace
.update_lock_file(UpdateLockFileOptions {
lock_file_usage: LockFileUsage::Update,
no_install: args.no_install_config.no_install,
lock_file_usage: if args.dry_run {
LockFileUsage::DryRun
} else {
LockFileUsage::Update
},
no_install: args.no_install_config.no_install || args.dry_run,
max_concurrent_solves: workspace.config().max_concurrent_solves(),
})
.await?;
Expand All @@ -62,6 +71,21 @@ pub async fn execute(args: Args) -> miette::Result<()> {
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 args.dry_run {
if !diff.is_empty() {
eprintln!(
"{}Dry-run: lock-file would be updated (not written to disk)",
console::style(console::Emoji("i ", "i ")).blue()
);
diff.print()
.into_diagnostic()
.context("failed to print lock-file diff")?;
} else {
eprintln!(
"{}Dry-run:lock file would not change",
console::style(console::Emoji("i ", "i ")).blue()
);
}
} else if lock_updated {
eprintln!(
"{}Updated lock-file",
Expand Down
3 changes: 3 additions & 0 deletions crates/pixi_core/src/environment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ pub enum LockFileUsage {
Locked,
/// Don't update the lock-file and don't check if it is out of date
Frozen,
/// Don't update the lock-file, but don't check if it is out of date
DryRun,
}

impl LockFileUsage {
Expand All @@ -474,6 +476,7 @@ impl LockFileUsage {
match self {
LockFileUsage::Update | LockFileUsage::Locked => true,
LockFileUsage::Frozen => false,
LockFileUsage::DryRun => false,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right!
With DryRun => true, the dependency resolution happens and the diff is computed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @johnnyg :)

}
}
}
Expand Down
5 changes: 4 additions & 1 deletion crates/pixi_core/src/lock_file/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ impl Workspace {
.await?;

// Write the lock-file to disk
lock_file_derived_data.write_to_disk()?;

if options.lock_file_usage != LockFileUsage::DryRun {
lock_file_derived_data.write_to_disk()?;
}

Ok((lock_file_derived_data, true))
}
Expand Down
2 changes: 2 additions & 0 deletions docs/reference/cli/pixi/lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pixi lock [OPTIONS]
: Output the changes in JSON format
- <a id="arg---check" href="#arg---check">`--check`</a>
: Check if any changes have been made to the lock file. If yes, exit with a non-zero code
- <a id="arg---dry-run" href="#arg---dry-run">`--dry-run`</a>
: Compute the lock file without writing to disk. Implies --no-install

## Update Options
- <a id="arg---no-install" href="#arg---no-install">`--no-install`</a>
Expand Down
Loading