Skip to content

Commit 5a7b59b

Browse files
delsnerpavelzw
andauthored
feat: Add --env-name flag for environment output directory (#59)
* 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]>
1 parent 87e6716 commit 5a7b59b

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "pixi-pack"
33
description = "A command line tool to pack and unpack conda environments for easy sharing"
4-
version = "0.2.0"
4+
version = "0.2.1"
55
edition = "2021"
66

77
[features]

src/main.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,16 @@ enum Commands {
6666
/// Unpack a pixi environment
6767
Unpack {
6868
/// Where to unpack the environment.
69-
/// The environment will be unpacked into a `env` subdirectory of this path.
69+
/// The environment will be unpacked into a subdirectory of this path
70+
/// (default `env`, change with `--env-name`).
7071
/// The activation script will be written to the root of this path.
7172
#[arg(short, long, default_value = cwd().into_os_string())]
7273
output_directory: PathBuf,
7374

75+
/// Name of the environment
76+
#[arg(short, long, default_value = "env")]
77+
env_name: String,
78+
7479
/// Path to the pack file
7580
#[arg()]
7681
pack_file: PathBuf,
@@ -122,12 +127,14 @@ async fn main() -> Result<()> {
122127
}
123128
Commands::Unpack {
124129
output_directory,
130+
env_name,
125131
pack_file,
126132
shell,
127133
} => {
128134
let options = UnpackOptions {
129135
pack_file,
130136
output_directory,
137+
env_name,
131138
shell,
132139
};
133140
tracing::debug!("Running unpack command with options: {:?}", options);

src/unpack.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use crate::{
3131
pub struct UnpackOptions {
3232
pub pack_file: PathBuf,
3333
pub output_directory: PathBuf,
34+
pub env_name: String,
3435
pub shell: Option<ShellEnum>,
3536
}
3637

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

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

50-
let target_prefix = options.output_directory.join("env");
51+
let target_prefix = options.output_directory.join(options.env_name);
5152

5253
tracing::info!("Creating prefix at {}", target_prefix.display());
5354
let channel_directory = unpack_dir.join(CHANNEL_DIRECTORY_NAME);

tests/integration_test.rs

+18
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ fn options(
2929
#[default(PixiPackMetadata::default())] metadata: PixiPackMetadata,
3030
#[default(Some(ShellEnum::Bash(Bash)))] shell: Option<ShellEnum>,
3131
#[default(false)] ignore_pypi_errors: bool,
32+
#[default("env")] env_name: String,
3233
) -> Options {
3334
let output_dir = tempdir().expect("Couldn't create a temp dir for tests");
3435
let pack_file = output_dir.path().join("environment.tar");
@@ -46,6 +47,7 @@ fn options(
4647
unpack_options: UnpackOptions {
4748
pack_file,
4849
output_directory: output_dir.path().to_path_buf(),
50+
env_name,
4951
shell,
5052
},
5153
output_dir,
@@ -335,3 +337,19 @@ async fn test_non_authenticated(
335337
.to_string()
336338
.contains("failed to download"));
337339
}
340+
341+
#[rstest]
342+
#[tokio::test]
343+
async fn test_custom_env_name(options: Options) {
344+
let env_name = "custom";
345+
let pack_options = options.pack_options;
346+
let pack_result = pixi_pack::pack(pack_options).await;
347+
assert!(pack_result.is_ok(), "{:?}", pack_result);
348+
349+
let mut unpack_options = options.unpack_options;
350+
unpack_options.env_name = env_name.to_string();
351+
let env_dir = unpack_options.output_directory.join(env_name);
352+
let unpack_result = pixi_pack::unpack(unpack_options).await;
353+
assert!(unpack_result.is_ok(), "{:?}", unpack_result);
354+
assert!(env_dir.is_dir());
355+
}

0 commit comments

Comments
 (0)