Skip to content

Commit

Permalink
use file to communicate from wheel build function (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Nov 27, 2023
1 parent a791a50 commit b02f946
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
25 changes: 23 additions & 2 deletions crates/rattler_installs_packages/src/wheel_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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)
}
}
16 changes: 10 additions & 6 deletions crates/rattler_installs_packages/src/wheel_builder_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,30 @@ 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"

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:]
Expand Down

0 comments on commit b02f946

Please sign in to comment.