Skip to content

Commit

Permalink
feat: Add --env-name flag for environment output directory (#59)
Browse files Browse the repository at this point in the history
* feat: Add --env-name flag for environment output directory

* Bump version to 0.2.1

* Update Cargo.lock

* Change cli docs

---------

Co-authored-by: Pavel Zwerschke <[email protected]>
  • Loading branch information
delsner and pavelzw authored Oct 24, 2024
1 parent 87e6716 commit 5a7b59b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "pixi-pack"
description = "A command line tool to pack and unpack conda environments for easy sharing"
version = "0.2.0"
version = "0.2.1"
edition = "2021"

[features]
Expand Down
9 changes: 8 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,16 @@ enum Commands {
/// Unpack a pixi environment
Unpack {
/// Where to unpack the environment.
/// The environment will be unpacked into a `env` subdirectory of this path.
/// The environment will be unpacked into a subdirectory of this path
/// (default `env`, change with `--env-name`).
/// The activation script will be written to the root of this path.
#[arg(short, long, default_value = cwd().into_os_string())]
output_directory: PathBuf,

/// Name of the environment
#[arg(short, long, default_value = "env")]
env_name: String,

/// Path to the pack file
#[arg()]
pack_file: PathBuf,
Expand Down Expand Up @@ -122,12 +127,14 @@ async fn main() -> Result<()> {
}
Commands::Unpack {
output_directory,
env_name,
pack_file,
shell,
} => {
let options = UnpackOptions {
pack_file,
output_directory,
env_name,
shell,
};
tracing::debug!("Running unpack command with options: {:?}", options);
Expand Down
3 changes: 2 additions & 1 deletion src/unpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use crate::{
pub struct UnpackOptions {
pub pack_file: PathBuf,
pub output_directory: PathBuf,
pub env_name: String,
pub shell: Option<ShellEnum>,
}

Expand All @@ -47,7 +48,7 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {

validate_metadata_file(unpack_dir.join(PIXI_PACK_METADATA_PATH)).await?;

let target_prefix = options.output_directory.join("env");
let target_prefix = options.output_directory.join(options.env_name);

tracing::info!("Creating prefix at {}", target_prefix.display());
let channel_directory = unpack_dir.join(CHANNEL_DIRECTORY_NAME);
Expand Down
18 changes: 18 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn options(
#[default(PixiPackMetadata::default())] metadata: PixiPackMetadata,
#[default(Some(ShellEnum::Bash(Bash)))] shell: Option<ShellEnum>,
#[default(false)] ignore_pypi_errors: bool,
#[default("env")] env_name: String,
) -> Options {
let output_dir = tempdir().expect("Couldn't create a temp dir for tests");
let pack_file = output_dir.path().join("environment.tar");
Expand All @@ -46,6 +47,7 @@ fn options(
unpack_options: UnpackOptions {
pack_file,
output_directory: output_dir.path().to_path_buf(),
env_name,
shell,
},
output_dir,
Expand Down Expand Up @@ -335,3 +337,19 @@ async fn test_non_authenticated(
.to_string()
.contains("failed to download"));
}

#[rstest]
#[tokio::test]
async fn test_custom_env_name(options: Options) {
let env_name = "custom";
let pack_options = options.pack_options;
let pack_result = pixi_pack::pack(pack_options).await;
assert!(pack_result.is_ok(), "{:?}", pack_result);

let mut unpack_options = options.unpack_options;
unpack_options.env_name = env_name.to_string();
let env_dir = unpack_options.output_directory.join(env_name);
let unpack_result = pixi_pack::unpack(unpack_options).await;
assert!(unpack_result.is_ok(), "{:?}", unpack_result);
assert!(env_dir.is_dir());
}

0 comments on commit 5a7b59b

Please sign in to comment.