Skip to content

Commit

Permalink
feat: expose dist-info folder after install (#91)
Browse files Browse the repository at this point in the history
Returns the `.dist-info` folder location after a wheel has been
unpacked.
  • Loading branch information
baszalmstra authored Nov 24, 2023
1 parent 30aa150 commit 2d7694d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 21 deletions.
4 changes: 2 additions & 2 deletions crates/rattler_installs_packages/src/venv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::system_python::{
system_python_executable, FindPythonError, ParsePythonInterpreterVersionError,
PythonInterpreterVersion,
};
use crate::wheel::UnpackError;
use crate::wheel::{UnpackError, UnpackedWheel};
use crate::{InstallPaths, UnpackWheelOptions, Wheel};
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
Expand Down Expand Up @@ -64,7 +64,7 @@ impl VEnv {
&self,
wheel: &Wheel,
options: &UnpackWheelOptions,
) -> Result<(), UnpackError> {
) -> Result<UnpackedWheel, UnpackError> {
wheel.unpack(&self.location, &self.install_paths, options)
}

Expand Down
43 changes: 24 additions & 19 deletions crates/rattler_installs_packages/src/wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Wheel {
}
}

#[allow(dead_code)]
#[derive(Debug)]
pub struct WheelVitals {
dist_info: String,
data: String,
Expand Down Expand Up @@ -535,6 +535,15 @@ pub struct UnpackWheelOptions {
pub installer: Option<String>,
}

#[derive(Debug)]
pub struct UnpackedWheel {
/// The path to the *.dist-info directory of the unpacked wheel.
pub dist_info: PathBuf,

/// The metadata of the wheel
pub metadata: WheelCoreMetadata,
}

impl Wheel {
/// Unpacks a wheel to the given filesystem.
/// TODO: Write better docs.
Expand All @@ -551,7 +560,7 @@ impl Wheel {
dest: &Path,
paths: &InstallPaths,
options: &UnpackWheelOptions,
) -> Result<(), UnpackError> {
) -> Result<UnpackedWheel, UnpackError> {
let vitals = self
.get_vitals()
.map_err(UnpackError::FailedToParseWheelVitals)?;
Expand Down Expand Up @@ -696,7 +705,10 @@ impl Wheel {
Record::from_iter(resulting_records)
.write_to_path(&site_packages.join(record_relative_path))?;

Ok(())
Ok(UnpackedWheel {
dist_info: site_packages.join(&vitals.dist_info),
metadata: vitals.metadata,
})
}
}

Expand Down Expand Up @@ -842,22 +854,20 @@ mod test {

struct UnpackedWheel {
tmpdir: TempDir,
vitals: WheelVitals,
install_paths: InstallPaths,
_metadata: WheelCoreMetadata,
dist_info: PathBuf,
_install_paths: InstallPaths,
}

fn unpack_wheel(path: &Path, normalized_package_name: &NormalizedPackageName) -> UnpackedWheel {
let wheel = Wheel::from_path(path, normalized_package_name).unwrap();
let tmpdir = tempdir().unwrap();

// Get the wheel vitals
let vitals = wheel.get_vitals().unwrap();

// Construct the path lookup to install packages to
let install_paths = InstallPaths::for_venv((3, 8, 5), false);

// Unpack the wheel
wheel
let unpacked = wheel
.unpack(
tmpdir.path(),
&install_paths,
Expand All @@ -869,8 +879,9 @@ mod test {

UnpackedWheel {
tmpdir,
vitals,
install_paths,
_metadata: unpacked.metadata,
dist_info: unpacked.dist_info,
_install_paths: install_paths,
}
}

Expand All @@ -882,10 +893,7 @@ mod test {
let unpacked = unpack_wheel(&path, &normalized_package_name);

// Determine the location where we would expect the RECORD file to exist
let record_path = unpacked
.install_paths
.site_packages()
.join(format!("{}/RECORD", unpacked.vitals.dist_info,));
let record_path = unpacked.dist_info.join("RECORD");
let record_content = std::fs::read_to_string(&unpacked.tmpdir.path().join(&record_path))
.unwrap_or_else(|_| panic!("failed to read RECORD from {}", record_path.display()));

Expand All @@ -901,10 +909,7 @@ mod test {
&"purelib-and-platlib".parse().unwrap(),
);

let relative_path = unpacked
.install_paths
.site_packages()
.join(format!("{}/INSTALLER", unpacked.vitals.dist_info));
let relative_path = unpacked.dist_info.join("INSTALLER");
let installer_content =
std::fs::read_to_string(unpacked.tmpdir.path().join(relative_path)).unwrap();
assert_eq!(installer_content, format!("{INSTALLER}\n"));
Expand Down

0 comments on commit 2d7694d

Please sign in to comment.