Skip to content

Commit

Permalink
Fix bdist_wheel.data_dir in the presence of local version segment g…
Browse files Browse the repository at this point in the history
…iven via `tag_build` (#550)

Co-authored-by: Alex Grönholm <[email protected]>
  • Loading branch information
abravalheri and agronholm authored Aug 5, 2023
1 parent dc945a5 commit e43f2fc
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/wheel/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 56 additions & 0 deletions tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import sys
import sysconfig
from inspect import cleandoc
from unittest.mock import Mock
from zipfile import ZipFile

Expand Down Expand Up @@ -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

0 comments on commit e43f2fc

Please sign in to comment.