From b02f946a0eed55a3e4e76b97c824c7378d0b8db3 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Mon, 27 Nov 2023 14:40:38 +0100 Subject: [PATCH] use file to communicate from wheel build function (#94) --- .../src/wheel_builder.rs | 25 +++++++++++++++++-- .../src/wheel_builder_frontend.py | 16 +++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/crates/rattler_installs_packages/src/wheel_builder.rs b/crates/rattler_installs_packages/src/wheel_builder.rs index 45efa7a8..4fc47356 100644 --- a/crates/rattler_installs_packages/src/wheel_builder.rs +++ b/crates/rattler_installs_packages/src/wheel_builder.rs @@ -396,6 +396,25 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { let output = build_environment.run_command("WheelMetadata")?; if !output.status.success() { + if output.status.code() == Some(50) { + tracing::warn!("SDist build backend does not support metadata generation"); + // build wheel instead + let wheel_file = self.build_wheel(sdist).await?; + let wheel = crate::wheel::Wheel::from_path( + &wheel_file, + &sdist.name().distribution.clone().into(), + ) + .map_err(|e| { + WheelBuildError::Error(format!( + "Could not build wheel for metadata extraction: {}", + e + )) + })?; + + return wheel.metadata().map_err(|e| { + WheelBuildError::Error(format!("Could not parse wheel metadata: {}", e)) + }); + } let stdout = String::from_utf8_lossy(&output.stderr); return Err(WheelBuildError::Error(stdout.to_string())); } @@ -423,8 +442,10 @@ impl<'db, 'i> WheelBuilder<'db, 'i> { return Err(WheelBuildError::Error(stdout.to_string())); } - let stdout = String::from_utf8_lossy(&output.stdout); - let wheel_file = PathBuf::from(stdout.trim()); + let result = + std::fs::read_to_string(build_environment.work_dir.path().join("wheel_result"))?; + let wheel_file = PathBuf::from(result.trim()); + Ok(wheel_file) } } diff --git a/crates/rattler_installs_packages/src/wheel_builder_frontend.py b/crates/rattler_installs_packages/src/wheel_builder_frontend.py index e6445ff8..23a1780b 100644 --- a/crates/rattler_installs_packages/src/wheel_builder_frontend.py +++ b/crates/rattler_installs_packages/src/wheel_builder_frontend.py @@ -80,7 +80,7 @@ def prepare_metadata_for_build_wheel(backend: ModuleType, work_dir: Path): # Write the path to the dist-info directory to a file result_file.write_text(result) else: - exit(123) + exit(50) def wheel_dirs(work_dir: Path): return work_dir / "wheel" @@ -88,18 +88,22 @@ def wheel_dirs(work_dir: Path): def build_wheel(backend: ModuleType, work_dir: Path): """Take a folder with an SDist and build a wheel from it.""" wheel_dir = wheel_dirs(work_dir) + result_file = work_dir / "wheel_result" - # TODO: maybe start reading this from the file again if it fails - metadata_dir = metadata_dirs(work_dir) / ".dist-info" - # Use the metadata directory if it exists, otherwise set this to None + # Use the metadata result if it exists, otherwise set this to None + metadata_result = work_dir / "metadata_result" + if metadata_result.exists(): + metadata_dir = metadata_result.read_text().strip() + else: + metadata_dir = None wheel_dir.mkdir() wheel_basename = backend.build_wheel( str(wheel_dir), - metadata_directory=metadata_dir if metadata_dir.exists() else None, + metadata_directory=metadata_dir, ) - print(str(wheel_dir / wheel_basename)) + result_file.write_text(str(wheel_dir / wheel_basename)) if __name__ == "__main__": work_dir, entry_point, goal = sys.argv[1:]