Skip to content

Commit 5a9b24c

Browse files
authored
fix the name of the .data directory in the generated wheel (#2449)
1 parent 5bcc730 commit 5a9b24c

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

src/build_context.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,11 @@ impl BuildContext {
637637
.context("Failed to add the files to the wheel")?;
638638

639639
self.add_pth(&mut writer)?;
640-
add_data(&mut writer, self.project_layout.data.as_deref())?;
640+
add_data(
641+
&mut writer,
642+
&self.metadata24,
643+
self.project_layout.data.as_deref(),
644+
)?;
641645
let wheel_path = writer.finish()?;
642646
Ok((wheel_path, format!("cp{major}{min_minor}")))
643647
}
@@ -715,7 +719,11 @@ impl BuildContext {
715719
.context("Failed to add the files to the wheel")?;
716720

717721
self.add_pth(&mut writer)?;
718-
add_data(&mut writer, self.project_layout.data.as_deref())?;
722+
add_data(
723+
&mut writer,
724+
&self.metadata24,
725+
self.project_layout.data.as_deref(),
726+
)?;
719727
let wheel_path = writer.finish()?;
720728
Ok((
721729
wheel_path,
@@ -838,7 +846,11 @@ impl BuildContext {
838846
)?;
839847

840848
self.add_pth(&mut writer)?;
841-
add_data(&mut writer, self.project_layout.data.as_deref())?;
849+
add_data(
850+
&mut writer,
851+
&self.metadata24,
852+
self.project_layout.data.as_deref(),
853+
)?;
842854
let wheel_path = writer.finish()?;
843855
Ok((wheel_path, "py3".to_string()))
844856
}
@@ -904,7 +916,11 @@ impl BuildContext {
904916
)?;
905917

906918
self.add_pth(&mut writer)?;
907-
add_data(&mut writer, self.project_layout.data.as_deref())?;
919+
add_data(
920+
&mut writer,
921+
&self.metadata24,
922+
self.project_layout.data.as_deref(),
923+
)?;
908924
let wheel_path = writer.finish()?;
909925
Ok((wheel_path, "py3".to_string()))
910926
}
@@ -1009,7 +1025,11 @@ impl BuildContext {
10091025
self.add_external_libs(&mut writer, &artifacts_ref, ext_libs)?;
10101026

10111027
self.add_pth(&mut writer)?;
1012-
add_data(&mut writer, self.project_layout.data.as_deref())?;
1028+
add_data(
1029+
&mut writer,
1030+
&self.metadata24,
1031+
self.project_layout.data.as_deref(),
1032+
)?;
10131033
let wheel_path = writer.finish()?;
10141034
Ok((wheel_path, "py3".to_string()))
10151035
}

src/metadata.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,15 @@ impl Metadata24 {
569569
&self.get_version_escaped()
570570
))
571571
}
572+
573+
/// Returns the name of the .data directory as defined in the wheel specification
574+
pub fn get_data_dir(&self) -> PathBuf {
575+
PathBuf::from(format!(
576+
"{}-{}.data",
577+
&self.get_distribution_escaped(),
578+
&self.get_version_escaped()
579+
))
580+
}
572581
}
573582

574583
/// Escape email addresses with display name if necessary

src/module_writer.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,7 +1485,11 @@ pub fn write_dist_info(
14851485
/// to save or generate the data in other places
14861486
///
14871487
/// See https://peps.python.org/pep-0427/#file-contents
1488-
pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<()> {
1488+
pub fn add_data(
1489+
writer: &mut impl ModuleWriter,
1490+
metadata24: &Metadata24,
1491+
data: Option<&Path>,
1492+
) -> Result<()> {
14891493
let possible_data_dir_names = ["data", "scripts", "headers", "purelib", "platlib"];
14901494
if let Some(data) = data {
14911495
for subdir in fs::read_dir(data).context("Failed to read data dir")? {
@@ -1513,7 +1517,9 @@ pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<(
15131517
let mode = file.metadata()?.permissions().mode();
15141518
#[cfg(not(unix))]
15151519
let mode = 0o644;
1516-
let relative = file.path().strip_prefix(data.parent().unwrap()).unwrap();
1520+
let relative = metadata24
1521+
.get_data_dir()
1522+
.join(file.path().strip_prefix(data).unwrap());
15171523

15181524
if file.path_is_symlink() {
15191525
// Copy the actual file contents, not the link, so that you can create a

0 commit comments

Comments
 (0)