Skip to content

Commit

Permalink
feat: add pixi lock (#3061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hofer-Julian authored Feb 4, 2025
1 parent 3f26136 commit d6a61d8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/cli/lock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use clap::Parser;

use crate::cli::cli_config::ProjectConfig;
use crate::environment::LockFileUsage;
use crate::lock_file::UpdateLockFileOptions;
use crate::Project;

/// Solve environment and update the lock file
#[derive(Debug, Parser)]
#[clap(arg_required_else_help = false)]
pub struct Args {
#[clap(flatten)]
pub project_config: ProjectConfig,
}

pub async fn execute(args: Args) -> miette::Result<()> {
let project = Project::load_or_else_discover(args.project_config.manifest_path.as_deref())?;

project
.update_lock_file(UpdateLockFileOptions {
lock_file_usage: LockFileUsage::Update,
no_install: true,
max_concurrent_solves: project.config().max_concurrent_solves(),
})
.await
.map(|_| ())
}
3 changes: 3 additions & 0 deletions src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub mod info;
pub mod init;
pub mod install;
pub mod list;
pub mod lock;
pub mod project;
pub mod remove;
pub mod run;
Expand Down Expand Up @@ -107,6 +108,7 @@ pub enum Command {
Install(install::Args),
Update(update::Args),
Upgrade(upgrade::Args),
Lock(lock::Args),

#[clap(visible_alias = "r")]
Run(run::Args),
Expand Down Expand Up @@ -281,6 +283,7 @@ pub async fn execute_command(command: Command) -> miette::Result<()> {
Command::Tree(cmd) => tree::execute(cmd).await,
Command::Update(cmd) => update::execute(cmd).await,
Command::Upgrade(cmd) => upgrade::execute(cmd).await,
Command::Lock(cmd) => lock::execute(cmd).await,
Command::Exec(args) => exec::execute(args).await,
Command::Build(args) => build::execute(args).await,
}
Expand Down
34 changes: 34 additions & 0 deletions tests/integration_python/test_main_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from pathlib import Path
import shutil

from .common import cwd, verify_cli_command, ExitCode, PIXI_VERSION, CURRENT_PLATFORM
import tomllib
Expand Down Expand Up @@ -960,3 +961,36 @@ def test_project_system_requirements(pixi: Path, tmp_pixi_workspace: Path) -> No
ExitCode.SUCCESS,
stdout_contains=["Linux: 10.1"],
)


def test_pixi_lock(pixi: Path, tmp_pixi_workspace: Path, dummy_channel_1: str) -> None:
manifest_path = tmp_pixi_workspace / "pixi.toml"
lock_file_path = tmp_pixi_workspace / "pixi.lock"

# Create a new project
verify_cli_command([pixi, "init", "--channel", dummy_channel_1, tmp_pixi_workspace])

# Add a dependency
verify_cli_command([pixi, "add", "--manifest-path", manifest_path, "dummy-a"])

# Read the original lock file content
original_lock_content = lock_file_path.read_text()

# Remove the lock file
lock_file_path.unlink()

# Remove the .pixi folder
dot_pixi = tmp_pixi_workspace / ".pixi"
shutil.rmtree(dot_pixi)

# Run pixi lock to recreate the lock file
verify_cli_command([pixi, "lock", "--manifest-path", manifest_path])

# Read the recreated lock file content
recreated_lock_content = lock_file_path.read_text()

# Check if the recreated lock file is the same as the original
assert original_lock_content == recreated_lock_content

# Ensure the .pixi folder does not exist
assert not dot_pixi.exists()

0 comments on commit d6a61d8

Please sign in to comment.