diff --git a/Cargo.lock b/Cargo.lock index eca90ba..7a6b17e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2343,7 +2343,7 @@ dependencies = [ [[package]] name = "pixi-pack" -version = "0.2.0" +version = "0.2.1" dependencies = [ "anyhow", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 5f2fec6..4358e21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/main.rs b/src/main.rs index 7344c55..5b586cf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, @@ -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); diff --git a/src/unpack.rs b/src/unpack.rs index 309b219..cdb84f1 100644 --- a/src/unpack.rs +++ b/src/unpack.rs @@ -31,6 +31,7 @@ use crate::{ pub struct UnpackOptions { pub pack_file: PathBuf, pub output_directory: PathBuf, + pub env_name: String, pub shell: Option, } @@ -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); diff --git a/tests/integration_test.rs b/tests/integration_test.rs index 3929848..efd4b8c 100644 --- a/tests/integration_test.rs +++ b/tests/integration_test.rs @@ -29,6 +29,7 @@ fn options( #[default(PixiPackMetadata::default())] metadata: PixiPackMetadata, #[default(Some(ShellEnum::Bash(Bash)))] shell: Option, #[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"); @@ -46,6 +47,7 @@ fn options( unpack_options: UnpackOptions { pack_file, output_directory: output_dir.path().to_path_buf(), + env_name, shell, }, output_dir, @@ -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()); +}