Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the name of the .data directory in the generated wheel #2449

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,11 @@ impl BuildContext {
.context("Failed to add the files to the wheel")?;

self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
add_data(
&mut writer,
&self.metadata24,
self.project_layout.data.as_deref(),
)?;
let wheel_path = writer.finish()?;
Ok((wheel_path, format!("cp{major}{min_minor}")))
}
Expand Down Expand Up @@ -715,7 +719,11 @@ impl BuildContext {
.context("Failed to add the files to the wheel")?;

self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
add_data(
&mut writer,
&self.metadata24,
self.project_layout.data.as_deref(),
)?;
let wheel_path = writer.finish()?;
Ok((
wheel_path,
Expand Down Expand Up @@ -838,7 +846,11 @@ impl BuildContext {
)?;

self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
add_data(
&mut writer,
&self.metadata24,
self.project_layout.data.as_deref(),
)?;
let wheel_path = writer.finish()?;
Ok((wheel_path, "py3".to_string()))
}
Expand Down Expand Up @@ -904,7 +916,11 @@ impl BuildContext {
)?;

self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
add_data(
&mut writer,
&self.metadata24,
self.project_layout.data.as_deref(),
)?;
let wheel_path = writer.finish()?;
Ok((wheel_path, "py3".to_string()))
}
Expand Down Expand Up @@ -1009,7 +1025,11 @@ impl BuildContext {
self.add_external_libs(&mut writer, &artifacts_ref, ext_libs)?;

self.add_pth(&mut writer)?;
add_data(&mut writer, self.project_layout.data.as_deref())?;
add_data(
&mut writer,
&self.metadata24,
self.project_layout.data.as_deref(),
)?;
let wheel_path = writer.finish()?;
Ok((wheel_path, "py3".to_string()))
}
Expand Down
9 changes: 9 additions & 0 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ impl Metadata24 {
&self.get_version_escaped()
))
}

/// Returns the name of the .data directory as defined in the wheel specification
pub fn get_data_dir(&self) -> PathBuf {
PathBuf::from(format!(
"{}-{}.data",
&self.get_distribution_escaped(),
&self.get_version_escaped()
))
}
}

/// Escape email addresses with display name if necessary
Expand Down
10 changes: 8 additions & 2 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,11 @@ pub fn write_dist_info(
/// to save or generate the data in other places
///
/// See https://peps.python.org/pep-0427/#file-contents
pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<()> {
pub fn add_data(
writer: &mut impl ModuleWriter,
metadata24: &Metadata24,
data: Option<&Path>,
) -> Result<()> {
let possible_data_dir_names = ["data", "scripts", "headers", "purelib", "platlib"];
if let Some(data) = data {
for subdir in fs::read_dir(data).context("Failed to read data dir")? {
Expand Down Expand Up @@ -1513,7 +1517,9 @@ pub fn add_data(writer: &mut impl ModuleWriter, data: Option<&Path>) -> Result<(
let mode = file.metadata()?.permissions().mode();
#[cfg(not(unix))]
let mode = 0o644;
let relative = file.path().strip_prefix(data.parent().unwrap()).unwrap();
let relative = metadata24
.get_data_dir()
.join(file.path().strip_prefix(data).unwrap());

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