Skip to content

Commit e7b66f5

Browse files
committed
First proposal of adding a flag to skip the platform check
1 parent 75ee03e commit e7b66f5

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

src/bin/pixi-unpack.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ struct Cli {
3838
#[arg(short, long)]
3939
shell: Option<ShellEnum>,
4040

41+
/// Flag to allow skipping the target platform check
42+
#[arg(long, action = clap::ArgAction::SetTrue)]
43+
allow_incompatible_target: bool,
44+
4145
#[command(subcommand)]
4246
command: Option<Commands>,
4347

@@ -74,6 +78,7 @@ async fn main() -> Result<()> {
7478
env_name,
7579
pack_file,
7680
shell,
81+
allow_incompatible_target,
7782
command,
7883
..
7984
} = cli;
@@ -89,6 +94,7 @@ async fn main() -> Result<()> {
8994
output_directory,
9095
env_name,
9196
shell,
97+
allow_incompatible_target,
9298
};
9399
tracing::debug!("Running unpack command with options: {:?}", options);
94100
unpack(options).await?;

src/unpack.rs

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub struct UnpackOptions {
4848
pub output_directory: PathBuf,
4949
pub env_name: String,
5050
pub shell: Option<ShellEnum>,
51+
pub allow_incompatible_target: bool,
5152
}
5253

5354
/// Unpack a pixi environment.
@@ -62,7 +63,7 @@ pub async fn unpack(options: UnpackOptions) -> Result<()> {
6263
.await
6364
.map_err(|e| anyhow!("Could not unarchive: {}", e))?;
6465

65-
validate_metadata_file(unpack_dir.join(PIXI_PACK_METADATA_PATH)).await?;
66+
validate_metadata_file(unpack_dir.join(PIXI_PACK_METADATA_PATH), options.allow_incompatible_target).await?;
6667

6768
// HACK: The `Installer` and `Preparer` created below (in `install_pypi_packages`),
6869
// will utilize rayon for parallelism. By using rayon
@@ -139,7 +140,7 @@ async fn collect_packages_in_subdir(subdir: PathBuf) -> Result<FxHashMap<String,
139140
Ok(conda_packages)
140141
}
141142

142-
async fn validate_metadata_file(metadata_file: PathBuf) -> Result<()> {
143+
async fn validate_metadata_file(metadata_file: PathBuf, allow_incompatible_target: bool) -> Result<()> {
143144
let metadata_contents = fs::read_to_string(&metadata_file)
144145
.await
145146
.map_err(|e| anyhow!("Could not read metadata file: {}", e))?;
@@ -150,7 +151,12 @@ async fn validate_metadata_file(metadata_file: PathBuf) -> Result<()> {
150151
anyhow::bail!("Unsupported pixi-pack version: {}", metadata.version);
151152
}
152153
if metadata.platform != Platform::current() {
153-
anyhow::bail!("The pack was created for a different platform");
154+
if allow_incompatible_target {
155+
tracing::warn!("The pack was created for a different platform, continuing because of flag --allow-incompatible-target")
156+
}
157+
else {
158+
anyhow::bail!("The pack was created for a different platform, if you still wish to continue, use --allow-incompatible-target");
159+
}
154160
}
155161

156162
tracing::debug!("pack metadata: {:?}", metadata);
@@ -461,7 +467,7 @@ mod tests {
461467
#[tokio::test]
462468
async fn test_metadata_file_valid(metadata_file: NamedTempFile) {
463469
assert!(
464-
validate_metadata_file(metadata_file.path().to_path_buf())
470+
validate_metadata_file(metadata_file.path().to_path_buf(), false)
465471
.await
466472
.is_ok()
467473
)
@@ -471,7 +477,7 @@ mod tests {
471477
#[tokio::test]
472478
async fn test_metadata_file_empty() {
473479
assert!(
474-
validate_metadata_file(NamedTempFile::new().unwrap().path().to_path_buf())
480+
validate_metadata_file(NamedTempFile::new().unwrap().path().to_path_buf(), false)
475481
.await
476482
.is_err()
477483
)
@@ -480,15 +486,15 @@ mod tests {
480486
#[rstest]
481487
#[tokio::test]
482488
async fn test_metadata_file_non_existent() {
483-
assert!(validate_metadata_file(PathBuf::new()).await.is_err())
489+
assert!(validate_metadata_file(PathBuf::new(), false).await.is_err())
484490
}
485491

486492
#[rstest]
487493
#[tokio::test]
488494
async fn test_metadata_file_invalid_version(
489495
#[with("v0".to_string())] metadata_file: NamedTempFile,
490496
) {
491-
let result = validate_metadata_file(metadata_file.path().to_path_buf()).await;
497+
let result = validate_metadata_file(metadata_file.path().to_path_buf(), false).await;
492498
let error = result.unwrap_err();
493499
assert_eq!(error.to_string(), "Unsupported pixi-pack version: v0");
494500
}
@@ -499,11 +505,21 @@ mod tests {
499505
#[with(DEFAULT_PIXI_PACK_VERSION.to_string(), other_platform())]
500506
metadata_file: NamedTempFile,
501507
) {
502-
let result = validate_metadata_file(metadata_file.path().to_path_buf()).await;
508+
let result = validate_metadata_file(metadata_file.path().to_path_buf(), false).await;
503509
let error = result.unwrap_err();
504510
assert_eq!(
505511
error.to_string(),
506-
"The pack was created for a different platform"
512+
"The pack was created for a different platform, if you still wish to continue, use --allow-incompatible-target"
513+
);
514+
}
515+
#[rstest]
516+
#[tokio::test]
517+
async fn test_metadata_file_wrong_platform_with_flag(
518+
#[with(DEFAULT_PIXI_PACK_VERSION.to_string(), other_platform())]
519+
metadata_file: NamedTempFile,
520+
) {
521+
assert!(validate_metadata_file(metadata_file.path().to_path_buf(), true).await
522+
.is_ok()
507523
);
508524
}
509525
}

tests/integration_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ fn options(
5454
pixi_pack_version: Some(PIXI_PACK_VERSION.to_string()),
5555
platform,
5656
};
57+
let allow_incompatible_target = false;
5758

5859
Options {
5960
pack_options: PackOptions {
@@ -75,6 +76,7 @@ fn options(
7576
output_directory: output_dir.path().to_path_buf(),
7677
env_name,
7778
shell,
79+
allow_incompatible_target,
7880
},
7981
output_dir,
8082
}

0 commit comments

Comments
 (0)