Skip to content

Commit

Permalink
remove unused argument in _manylinux._is_compatible (pypa#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayeut authored Jul 7, 2023
1 parent 2b389f3 commit 538cd15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/packaging/_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -231,10 +231,10 @@ def platform_tags(linux: str, arch: 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 linux.replace("linux", tag)
# 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 linux.replace("linux", legacy_tag)
12 changes: 6 additions & 6 deletions tests/test_manylinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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(
Expand All @@ -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"])
Expand Down Expand Up @@ -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(
Expand Down
47 changes: 27 additions & 20 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pytest

from packaging import tags
from packaging._manylinux import _GLibCVersion
from packaging._musllinux import _MuslVersion


Expand Down Expand Up @@ -383,33 +384,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

Expand Down Expand Up @@ -445,7 +450,7 @@ def test_linux_platforms_manylinux2014_armhf_abi(self, monkeypatch):
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: "linux_armv7l")
monkeypatch.setattr(
Expand All @@ -458,7 +463,7 @@ def test_linux_platforms_manylinux2014_armhf_abi(self, monkeypatch):
),
)
platforms = list(tags._linux_platforms(is_32bit=True))
expected = ["manylinux2014_armv7l", "linux_armv7l"]
expected = ["manylinux_2_17_armv7l", "manylinux2014_armv7l", "linux_armv7l"]
assert platforms == expected

def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch):
Expand Down Expand Up @@ -498,7 +503,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,
Expand Down Expand Up @@ -553,7 +558,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)
Expand All @@ -568,7 +575,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,
Expand Down

0 comments on commit 538cd15

Please sign in to comment.