Skip to content

Commit

Permalink
Fix wheel file naming
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Dec 9, 2024
1 parent 9692cde commit 8112d0c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 7 additions & 1 deletion setuptools/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ def filename_component_broken(value: str) -> str:
def safer_name(value: str) -> str:
"""Like ``safe_name`` but can be used as filename component for wheel"""
# See bdist_wheel.safer_name
return filename_component(safe_name(value))
return (
# Per https://packaging.python.org/en/latest/specifications/name-normalization/#name-normalization
re.sub(r"[-_.]+", "-", safe_name(value))
.lower()
# Per https://packaging.python.org/en/latest/specifications/binary-distribution-format/#escaping-and-unicode
.replace("-", "_")
)


def safer_best_effort_version(value: str) -> str:
Expand Down
14 changes: 10 additions & 4 deletions setuptools/command/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ def get_abi_tag() -> str | None:


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


def safer_version(version: str) -> str:
Expand Down Expand Up @@ -364,9 +370,9 @@ def get_tag(self) -> tuple[str, str, str]:
supported_tags = [
(t.interpreter, t.abi, plat_name) for t in tags.sys_tags()
]
assert tag in supported_tags, (
f"would build wheel with unsupported tag {tag}"
)
assert (
tag in supported_tags
), f"would build wheel with unsupported tag {tag}"
return tag

def run(self):
Expand Down
4 changes: 2 additions & 2 deletions setuptools/tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ def test_no_scripts(wheel_paths):


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

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

Expand Down
2 changes: 1 addition & 1 deletion setuptools/tests/test_dist_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_dist_info_is_the_same_as_in_wheel(
dist_info = next(tmp_path.glob("dir_dist/*.dist-info"))

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

Expand Down

0 comments on commit 8112d0c

Please sign in to comment.