Add PackageName::as_dist_info_name (#305)

From
https://packaging.python.org/en/latest/specifications/recording-installed-packages/#recording-installed-packages

> This directory is named as {name}-{version}.dist-info, with name and
version fields corresponding to Core metadata specifications. Both
fields must be normalized (see Package name normalization and PEP 440
for the definition of normalization for each field respectively), and
replace dash (-) characters with underscore (_) characters, so the
.dist-info directory always has exactly one dash (-) character in its
stem, separating the name and version fields.

Follow up to #278
This commit is contained in:
konsti
2023-11-03 09:16:44 +01:00
committed by GitHub
parent e47d3f1f66
commit e008c43f29
2 changed files with 13 additions and 2 deletions
+6 -2
View File
@@ -1030,8 +1030,12 @@ pub fn find_dist_info(
filename: &WheelFilename,
archive: &mut ZipArchive<impl Read + Seek + Sized>,
) -> Result<String, Error> {
let dist_info_matcher =
format!("{}-{}", filename.distribution, filename.version).to_lowercase();
let dist_info_matcher = format!(
"{}-{}",
filename.distribution.as_dist_info_name(),
filename.version
)
.to_lowercase();
let dist_infos: Vec<_> = archive
.file_names()
.filter_map(|name| name.split_once('/'))
@@ -36,6 +36,13 @@ impl PackageName {
normalized.make_ascii_lowercase();
Self(normalized)
}
/// Escape this name with underscores (`_`) instead of dashes (`-`)
///
/// See: <https://packaging.python.org/en/latest/specifications/recording-installed-packages/#recording-installed-packages>
pub fn as_dist_info_name(&self) -> String {
self.0.replace('-', "_")
}
}
impl AsRef<str> for PackageName {