Skip to content

Commit

Permalink
Merge pull request #4617 from abravalheri/issue-4612
Browse files Browse the repository at this point in the history
Deprecate `bdist_wheel.universal`
  • Loading branch information
jaraco authored Sep 15, 2024
2 parents cd3ba7d + 1f5f6be commit 9fb53fd
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions newsfragments/4617.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Deprecated ``bdist_wheel.universal`` configuration.
18 changes: 16 additions & 2 deletions setuptools/command/bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from wheel.wheelfile import WheelFile

from .. import Command, __version__
from ..warnings import SetuptoolsDeprecationWarning
from .egg_info import egg_info as egg_info_cls

from distutils import log
Expand Down Expand Up @@ -205,7 +206,7 @@ class bdist_wheel(Command):
"g",
"Group name used when creating a tar file [default: current group]",
),
("universal", None, "make a universal wheel [default: false]"),
("universal", None, "*DEPRECATED* make a universal wheel [default: false]"),
(
"compression=",
None,
Expand Down Expand Up @@ -278,13 +279,26 @@ def finalize_options(self) -> None:

# Support legacy [wheel] section for setting universal
wheel = self.distribution.get_option_dict("wheel")
if "universal" in wheel:
if "universal" in wheel: # pragma: no cover
# please don't define this in your global configs
log.warn("The [wheel] section is deprecated. Use [bdist_wheel] instead.")
val = wheel["universal"][1].strip()
if val.lower() in ("1", "true", "yes"):
self.universal = True

if self.universal:
SetuptoolsDeprecationWarning.emit(
"bdist_wheel.universal is deprecated",
"""
With Python 2.7 end-of-life, support for building universal wheels
(i.e., wheels that support both Python 2 and Python 3)
is being obviated.
Please discontinue using this option, or if you still need it,
file an issue with pypa/setuptools describing your use case.
""",
due_date=(2025, 8, 30), # Introduced in 2024-08-30
)

if self.build_number is not None and not self.build_number[:1].isdigit():
raise ValueError("Build tag (build-number) must start with a digit.")

Expand Down
39 changes: 24 additions & 15 deletions setuptools/tests/test_bdist_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
remove_readonly_exc,
)
from setuptools.dist import Distribution
from setuptools.warnings import SetuptoolsDeprecationWarning

from distutils.core import run_setup

Expand Down Expand Up @@ -123,7 +124,6 @@
)
"""
),
"setup.cfg": "[bdist_wheel]\nuniversal=1",
"headersdist.py": "",
"header.h": "",
},
Expand Down Expand Up @@ -300,8 +300,8 @@ def license_paths(self):

def test_licenses_default(dummy_dist, monkeypatch, tmp_path):
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()
with ZipFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
license_files = {
"dummy_dist-1.0.dist-info/" + fname for fname in DEFAULT_LICENSE_FILES
}
Expand All @@ -314,9 +314,9 @@ def test_licenses_deprecated(dummy_dist, monkeypatch, tmp_path):
)
monkeypatch.chdir(dummy_dist)

bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()

with ZipFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
license_files = {"dummy_dist-1.0.dist-info/DUMMYFILE"}
assert set(wf.namelist()) == DEFAULT_FILES | license_files

Expand All @@ -337,8 +337,8 @@ def test_licenses_deprecated(dummy_dist, monkeypatch, tmp_path):
def test_licenses_override(dummy_dist, monkeypatch, tmp_path, config_file, config):
dummy_dist.joinpath(config_file).write_text(config, encoding="utf-8")
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()
with ZipFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
license_files = {
"dummy_dist-1.0.dist-info/" + fname for fname in {"DUMMYFILE", "LICENSE"}
}
Expand All @@ -350,20 +350,29 @@ def test_licenses_disabled(dummy_dist, monkeypatch, tmp_path):
"[metadata]\nlicense_files=\n", encoding="utf-8"
)
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()
with ZipFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path)).run()
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
assert set(wf.namelist()) == DEFAULT_FILES


def test_build_number(dummy_dist, monkeypatch, tmp_path):
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2", universal=True).run()
with ZipFile("dist/dummy_dist-1.0-2-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2").run()
with ZipFile("dist/dummy_dist-1.0-2-py3-none-any.whl") as wf:
filenames = set(wf.namelist())
assert "dummy_dist-1.0.dist-info/RECORD" in filenames
assert "dummy_dist-1.0.dist-info/METADATA" in filenames


def test_universal_deprecated(dummy_dist, monkeypatch, tmp_path):
monkeypatch.chdir(dummy_dist)
with pytest.warns(SetuptoolsDeprecationWarning, match=".*universal is deprecated"):
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True).run()

# For now we still respect the option
assert os.path.exists("dist/dummy_dist-1.0-py2.py3-none-any.whl")


EXTENSION_EXAMPLE = """\
#include <Python.h>
Expand Down Expand Up @@ -431,8 +440,8 @@ def test_build_from_readonly_tree(dummy_dist, monkeypatch, tmp_path):
)
def test_compression(dummy_dist, monkeypatch, tmp_path, option, compress_type):
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), universal=True, compression=option).run()
with ZipFile("dist/dummy_dist-1.0-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path), compression=option).run()
with ZipFile("dist/dummy_dist-1.0-py3-none-any.whl") as wf:
filenames = set(wf.namelist())
assert "dummy_dist-1.0.dist-info/RECORD" in filenames
assert "dummy_dist-1.0.dist-info/METADATA" in filenames
Expand All @@ -451,8 +460,8 @@ def test_wheelfile_line_endings(wheel_paths):
def test_unix_epoch_timestamps(dummy_dist, monkeypatch, tmp_path):
monkeypatch.setenv("SOURCE_DATE_EPOCH", "0")
monkeypatch.chdir(dummy_dist)
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2a", universal=True).run()
with ZipFile("dist/dummy_dist-1.0-2a-py2.py3-none-any.whl") as wf:
bdist_wheel_cmd(bdist_dir=str(tmp_path), build_number="2a").run()
with ZipFile("dist/dummy_dist-1.0-2a-py3-none-any.whl") as wf:
for zinfo in wf.filelist:
assert zinfo.date_time >= (1980, 1, 1, 0, 0, 0) # min epoch is used

Expand Down
3 changes: 0 additions & 3 deletions setuptools/tests/test_build_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,6 @@ def test_build_with_pyproject_config(self, tmpdir, setup_script):
[tool.distutils.sdist]
formats = "gztar"
[tool.distutils.bdist_wheel]
universal = true
"""
),
"MANIFEST.in": DALS(
Expand Down

0 comments on commit 9fb53fd

Please sign in to comment.