Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add --env-name flag for environment output directory #59

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 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
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ enum Commands {
#[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 +126,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());
}
Loading