From 83d425d1efe433dccb56ee89a726f50e7e5e9536 Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Mon, 9 Dec 2024 23:56:00 +0000 Subject: [PATCH 1/2] Fix wheel file naming --- setuptools/_normalization.py | 8 +++++++- setuptools/command/bdist_wheel.py | 14 ++++++++++---- setuptools/tests/test_bdist_wheel.py | 4 ++-- setuptools/tests/test_dist_info.py | 2 +- 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/setuptools/_normalization.py b/setuptools/_normalization.py index 467b643d46..9541a55d6c 100644 --- a/setuptools/_normalization.py +++ b/setuptools/_normalization.py @@ -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: diff --git a/setuptools/command/bdist_wheel.py b/setuptools/command/bdist_wheel.py index 234df2a7c7..2f129481fa 100644 --- a/setuptools/command/bdist_wheel.py +++ b/setuptools/command/bdist_wheel.py @@ -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: @@ -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): diff --git a/setuptools/tests/test_bdist_wheel.py b/setuptools/tests/test_bdist_wheel.py index d51dfbeb6d..776d21d729 100644 --- a/setuptools/tests/test_bdist_wheel.py +++ b/setuptools/tests/test_bdist_wheel.py @@ -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 diff --git a/setuptools/tests/test_dist_info.py b/setuptools/tests/test_dist_info.py index 31e6e95a68..426694e019 100644 --- a/setuptools/tests/test_dist_info.py +++ b/setuptools/tests/test_dist_info.py @@ -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) From c1bf7c76ace9eec1de1a6fb807787eb3ab51022a Mon Sep 17 00:00:00 2001 From: Dustin Ingram Date: Mon, 9 Dec 2024 23:59:43 +0000 Subject: [PATCH 2/2] Fix bug in test --- setuptools/tests/test_easy_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py index 586324be37..f7a39c8ca6 100644 --- a/setuptools/tests/test_easy_install.py +++ b/setuptools/tests/test_easy_install.py @@ -719,7 +719,7 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): # running the setup.py at all is sufficient run_setup(test_setup_py, ['--name']) except pkg_resources.VersionConflict: - self.fail( + pytest.fail( 'Installing setup.py requirements caused a VersionConflict' )