From 69aeff024dc929bcaf28f747a5af4c987ed9a804 Mon Sep 17 00:00:00 2001 From: Arto Bendiken Date: Mon, 2 Feb 2026 09:31:48 -0800 Subject: [PATCH] Normalize wheel distribution names to match the PyPA spec. This fixes building publishable sdists and wheels for packages where the name contains a period. For example, "asimov.py" is normalized into "asimov_py". --- src/build_context.rs | 8 -------- src/metadata.rs | 14 ++++++++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/build_context.rs b/src/build_context.rs index 9f302189d..f0fd4aecd 100644 --- a/src/build_context.rs +++ b/src/build_context.rs @@ -1035,14 +1035,6 @@ impl BuildContext { if self.target.is_wasi() { eprintln!("⚠️ Warning: wasi support is experimental"); - // escaped can contain [\w\d.], but i don't know how we'd handle dots correctly here - if self.metadata24.get_distribution_escaped().contains('.') { - bail!( - "Can't build wasm wheel if there is a dot in the name ('{}')", - self.metadata24.get_distribution_escaped() - ) - } - if !self.metadata24.entry_points.is_empty() { bail!("You can't define entrypoints yourself for a binary project"); } diff --git a/src/metadata.rs b/src/metadata.rs index 345ebe333..bf01eec81 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -652,11 +652,17 @@ impl Metadata24 { Ok(out) } - /// Returns the distribution name according to PEP 427, Section "Escaping - /// and Unicode" + /// Returns the distribution name normalized according to the PyPA Binary + /// Distribution Format specification. + /// + /// This is the name that will be used in the wheel filename and for the + /// `.dist-info` directory name. It is also the name that will be used in + /// the source distribution (sdist) filename. + /// + /// See https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode pub fn get_distribution_escaped(&self) -> String { - let re = Regex::new(r"[^\w\d.]+").unwrap(); - re.replace_all(&self.name, "_").to_string() + let re = Regex::new(r"[-_.]+").unwrap(); + re.replace_all(&self.name, "_").to_lowercase() } /// Returns the version encoded according to PEP 427, Section "Escaping