diff --git a/docs/news.rst b/docs/news.rst index 51bd5a8a..f7b61cba 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -1,6 +1,11 @@ Release Notes ============= +**UNRELEASED** + +- Fix naming of the ``data_dir`` directory in the presence of local version segment + given via ``egg_info.tag_build`` (PR by Anderson Bravalheri) + **0.41.0 (2023-07-22)** - Added full support of the build tag syntax to ``wheel tags`` (you can now set a build diff --git a/src/wheel/bdist_wheel.py b/src/wheel/bdist_wheel.py index 2f93c473..c8ee2adc 100644 --- a/src/wheel/bdist_wheel.py +++ b/src/wheel/bdist_wheel.py @@ -232,6 +232,9 @@ def finalize_options(self): bdist_base = self.get_finalized_command("bdist").bdist_base self.bdist_dir = os.path.join(bdist_base, "wheel") + egg_info = self.distribution.get_command_obj("egg_info") + egg_info.ensure_finalized() # needed for correct `wheel_dist_name` + self.data_dir = self.wheel_dist_name + ".data" self.plat_name_supplied = self.plat_name is not None diff --git a/tests/test_bdist_wheel.py b/tests/test_bdist_wheel.py index d2024691..b7c04b27 100644 --- a/tests/test_bdist_wheel.py +++ b/tests/test_bdist_wheel.py @@ -6,6 +6,7 @@ import subprocess import sys import sysconfig +from inspect import cleandoc from unittest.mock import Mock from zipfile import ZipFile @@ -329,3 +330,58 @@ def test_rmtree_readonly(monkeypatch, tmp_path, capsys): if expected_count: captured = capsys.readouterr() assert "file.txt" in captured.stdout + + +def test_data_dir_with_tag_build(monkeypatch, tmp_path): + """ + Setuptools allow authors to set PEP 440's local version segments + using ``egg_info.tag_build``. This should be reflected not only in the + ``.whl`` file name, but also in the ``.dist-info`` and ``.data`` dirs. + See pypa/setuptools#3997. + """ + monkeypatch.chdir(tmp_path) + files = { + "setup.py": """ + from setuptools import setup + setup(headers=["hello.h"]) + """, + "setup.cfg": """ + [metadata] + name = test + version = 1.0 + + [options.data_files] + hello/world = file.txt + + [egg_info] + tag_build = +what + tag_date = 0 + """, + "file.txt": "", + "hello.h": "", + } + for file, content in files.items(): + with open(file, "w", encoding="utf-8") as fh: + fh.write(cleandoc(content)) + + subprocess.check_call([sys.executable, "setup.py", "bdist_wheel"]) + + # Ensure .whl, .dist-info and .data contain the local segment + wheel_path = "dist/test-1.0+what-py3-none-any.whl" + assert os.path.exists(wheel_path) + entries = set(ZipFile(wheel_path).namelist()) + for expected in ( + "test-1.0+what.data/headers/hello.h", + "test-1.0+what.data/data/hello/world/file.txt", + "test-1.0+what.dist-info/METADATA", + "test-1.0+what.dist-info/WHEEL", + ): + assert expected in entries + + for not_expected in ( + "test.data/headers/hello.h", + "test-1.0.data/data/hello/world/file.txt", + "test.dist-info/METADATA", + "test-1.0.dist-info/WHEEL", + ): + assert not_expected not in entries