Skip to content

Commit 83d425d

Browse files
diabravalheri
authored andcommitted
Fix wheel file naming
1 parent cc43212 commit 83d425d

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

setuptools/_normalization.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ def filename_component_broken(value: str) -> str:
134134
def safer_name(value: str) -> str:
135135
"""Like ``safe_name`` but can be used as filename component for wheel"""
136136
# See bdist_wheel.safer_name
137-
return filename_component(safe_name(value))
137+
return (
138+
# Per https://packaging.python.org/en/latest/specifications/name-normalization/#name-normalization
139+
re.sub(r"[-_.]+", "-", safe_name(value))
140+
.lower()
141+
# Per https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
142+
.replace("-", "_")
143+
)
138144

139145

140146
def safer_best_effort_version(value: str) -> str:

setuptools/command/bdist_wheel.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ def get_abi_tag() -> str | None:
134134

135135

136136
def safer_name(name: str) -> str:
137-
return safe_name(name).replace("-", "_")
137+
return (
138+
# Per https://packaging.python.org/en/latest/specifications/name-normalization/#name-normalization
139+
re.sub(r"[-_.]+", "-", safe_name(name))
140+
.lower()
141+
# Per https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
142+
.replace("-", "_")
143+
)
138144

139145

140146
def safer_version(version: str) -> str:
@@ -364,9 +370,9 @@ def get_tag(self) -> tuple[str, str, str]:
364370
supported_tags = [
365371
(t.interpreter, t.abi, plat_name) for t in tags.sys_tags()
366372
]
367-
assert tag in supported_tags, (
368-
f"would build wheel with unsupported tag {tag}"
369-
)
373+
assert (
374+
tag in supported_tags
375+
), f"would build wheel with unsupported tag {tag}"
370376
return tag
371377

372378
def run(self):

setuptools/tests/test_bdist_wheel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,9 @@ def test_no_scripts(wheel_paths):
246246

247247

248248
def test_unicode_record(wheel_paths):
249-
path = next(path for path in wheel_paths if "unicode.dist" in path)
249+
path = next(path for path in wheel_paths if "unicode_dist" in path)
250250
with ZipFile(path) as zf:
251-
record = zf.read("unicode.dist-0.1.dist-info/RECORD")
251+
record = zf.read("unicode_dist-0.1.dist-info/RECORD")
252252

253253
assert "åäö_日本語.py".encode() in record
254254

setuptools/tests/test_dist_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_dist_info_is_the_same_as_in_wheel(
188188
dist_info = next(tmp_path.glob("dir_dist/*.dist-info"))
189189

190190
assert dist_info.name == wheel_dist_info.name
191-
assert dist_info.name.startswith(f"{name.replace('-', '_')}-{version}{suffix}")
191+
assert dist_info.name.startswith(f"my_proj-{version}{suffix}")
192192
for file in "METADATA", "entry_points.txt":
193193
assert read(dist_info / file) == read(wheel_dist_info / file)
194194

0 commit comments

Comments
 (0)