From fdcf5dceccc0681ff0155c4c7e54e30bb62cf3ce Mon Sep 17 00:00:00 2001 From: mayeut Date: Sun, 18 Jun 2023 13:20:38 +0200 Subject: [PATCH] remove unused argument in `_manylinux._is_compatible` --- src/packaging/_manylinux.py | 6 ++--- tests/test_manylinux.py | 12 ++++----- tests/test_tags.py | 52 +++++++++++++++++++++---------------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/src/packaging/_manylinux.py b/src/packaging/_manylinux.py index 9cd1d37d..5eb2ab70 100644 --- a/src/packaging/_manylinux.py +++ b/src/packaging/_manylinux.py @@ -167,7 +167,7 @@ def _get_glibc_version() -> Tuple[int, int]: # From PEP 513, PEP 600 -def _is_compatible(name: str, arch: str, version: _GLibCVersion) -> bool: +def _is_compatible(arch: str, version: _GLibCVersion) -> bool: sys_glibc = _get_glibc_version() if sys_glibc < version: return False @@ -242,10 +242,10 @@ def platform_tags(archs: Sequence[str]) -> Iterator[str]: for glibc_minor in range(glibc_max.minor, min_minor, -1): glibc_version = _GLibCVersion(glibc_max.major, glibc_minor) tag = "manylinux_{}_{}".format(*glibc_version) - if _is_compatible(tag, arch, glibc_version): + if _is_compatible(arch, glibc_version): yield f"{tag}_{arch}" # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags. if glibc_version in _LEGACY_MANYLINUX_MAP: legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version] - if _is_compatible(legacy_tag, arch, glibc_version): + if _is_compatible(arch, glibc_version): yield f"{legacy_tag}_{arch}" diff --git a/tests/test_manylinux.py b/tests/test_manylinux.py index 3561bb99..e588912a 100644 --- a/tests/test_manylinux.py +++ b/tests/test_manylinux.py @@ -46,7 +46,7 @@ def manylinux_module(monkeypatch): def test_module_declaration(monkeypatch, manylinux_module, attribute, glibc, tf): manylinux = f"manylinux{attribute}_compatible" monkeypatch.setattr(manylinux_module, manylinux, tf, raising=False) - res = _is_compatible(manylinux, "x86_64", glibc) + res = _is_compatible("x86_64", glibc) assert tf is res @@ -58,7 +58,7 @@ def test_module_declaration_missing_attribute( ): manylinux = f"manylinux{attribute}_compatible" monkeypatch.delattr(manylinux_module, manylinux, raising=False) - assert _is_compatible(manylinux, "x86_64", glibc) + assert _is_compatible("x86_64", glibc) @pytest.mark.parametrize( @@ -67,7 +67,7 @@ def test_module_declaration_missing_attribute( def test_is_manylinux_compatible_glibc_support(version, compatible, monkeypatch): monkeypatch.setitem(sys.modules, "_manylinux", None) monkeypatch.setattr(_manylinux, "_get_glibc_version", lambda: (2, 5)) - assert bool(_is_compatible("manylinux1", "any", version)) == compatible + assert bool(_is_compatible("any", version)) == compatible @pytest.mark.parametrize("version_str", ["glibc-2.4.5", "2"]) @@ -152,17 +152,17 @@ def patched_cdll(name): def test_is_manylinux_compatible_old(): # Assuming no one is running this test with a version of glibc released in # 1997. - assert _is_compatible("any", "any", (2, 0)) + assert _is_compatible("any", (2, 0)) def test_is_manylinux_compatible(monkeypatch): monkeypatch.setattr(_manylinux, "_glibc_version_string", lambda: "2.4") - assert _is_compatible("", "any", (2, 4)) + assert _is_compatible("any", (2, 4)) def test_glibc_version_string_none(monkeypatch): monkeypatch.setattr(_manylinux, "_glibc_version_string", lambda: None) - assert not _is_compatible("any", "any", (2, 4)) + assert not _is_compatible("any", (2, 4)) @pytest.mark.parametrize( diff --git a/tests/test_tags.py b/tests/test_tags.py index cade2388..870ef4ec 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -21,6 +21,7 @@ import pytest from packaging import tags +from packaging._manylinux import _GLibCVersion from packaging._musllinux import _MuslVersion @@ -385,33 +386,37 @@ def test_linux_platforms_manylinux_unsupported(self, monkeypatch): def test_linux_platforms_manylinux1(self, monkeypatch): monkeypatch.setattr( - tags._manylinux, "_is_compatible", lambda name, *args: name == "manylinux1" + tags._manylinux, + "_is_compatible", + lambda _, glibc_version: glibc_version == _GLibCVersion(2, 5), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) - arch = platform.machine() - assert platforms == ["manylinux1_" + arch, "linux_" + arch] + assert platforms == [ + "manylinux_2_5_x86_64", + "manylinux1_x86_64", + "linux_x86_64", + ] def test_linux_platforms_manylinux2010(self, monkeypatch): monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_x86_64") monkeypatch.setattr(platform, "machine", lambda: "x86_64") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.12", raising=False) platforms = list(tags._linux_platforms(is_32bit=False)) - arch = platform.machine() expected = [ - "manylinux_2_12_" + arch, - "manylinux2010_" + arch, - "manylinux_2_11_" + arch, - "manylinux_2_10_" + arch, - "manylinux_2_9_" + arch, - "manylinux_2_8_" + arch, - "manylinux_2_7_" + arch, - "manylinux_2_6_" + arch, - "manylinux_2_5_" + arch, - "manylinux1_" + arch, - "linux_" + arch, + "manylinux_2_12_x86_64", + "manylinux2010_x86_64", + "manylinux_2_11_x86_64", + "manylinux_2_10_x86_64", + "manylinux_2_9_x86_64", + "manylinux_2_8_x86_64", + "manylinux_2_7_x86_64", + "manylinux_2_6_x86_64", + "manylinux_2_5_x86_64", + "manylinux1_x86_64", + "linux_x86_64", ] assert platforms == expected @@ -453,7 +458,7 @@ def test_linux_platforms_manylinux2014_armhf_abi( monkeypatch.setattr( tags._manylinux, "_is_compatible", - lambda name, *args: name == "manylinux2014", + lambda _, glibc_version: glibc_version == _GLibCVersion(2, 17), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: f"linux_{native_arch}") monkeypatch.setattr( @@ -467,9 +472,10 @@ def test_linux_platforms_manylinux2014_armhf_abi( ) platforms = list(tags._linux_platforms(is_32bit=True)) archs = {"armv8l": ["armv8l", "armv7l"]}.get(cross_arch, [cross_arch]) - expected = [f"manylinux2014_{arch}" for arch in archs] + [ - f"linux_{arch}" for arch in archs - ] + expected = [] + for arch in archs: + expected.extend([f"manylinux_2_17_{arch}", f"manylinux2014_{arch}"]) + expected.extend(f"linux_{arch}" for arch in archs) assert platforms == expected def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch): @@ -509,7 +515,7 @@ def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch): def test_linux_platforms_manylinux_glibc3(self, monkeypatch): # test for a future glic 3.x version monkeypatch.setattr(tags._manylinux, "_glibc_version_string", lambda: "3.2") - monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda name, *args: True) + monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda *args: True) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_aarch64") monkeypatch.setattr( sys, @@ -569,7 +575,9 @@ def test_linux_platforms_musllinux( def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch): monkeypatch.setattr( - tags._manylinux, "_is_compatible", lambda name, _: name == "manylinux2014" + tags._manylinux, + "_is_compatible", + lambda _, glibc_version: glibc_version == _GLibCVersion(2, 17), ) monkeypatch.setattr(sysconfig, "get_platform", lambda: "linux_armv6l") monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False) @@ -584,7 +592,7 @@ def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch): def test_linux_platforms_not_manylinux_abi( self, monkeypatch, machine, abi, alt_machine ): - monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda name, _: False) + monkeypatch.setattr(tags._manylinux, "_is_compatible", lambda *args: False) monkeypatch.setattr(sysconfig, "get_platform", lambda: f"linux_{machine}") monkeypatch.setattr( sys,