Skip to content

Commit

Permalink
reverse order, add test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Apr 10, 2020
1 parent 7e81d5d commit f432bcd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 29 deletions.
45 changes: 17 additions & 28 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,48 +664,37 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
linux = "linux_armv7l"
manylinux_support = []
_, arch = linux.split("_", 1)
pep600_support = []
if _have_compatible_manylinux_abi(arch):
if arch in {"x86_64", "i686", "aarch64", "armv7l", "ppc64", "ppc64le", "s390x"}:
manylinux_support.append(
("manylinux2014", (2, 17))
) # CentOS 7 w/ glibc 2.17 (PEP 599)
if arch in ("x86_64", "i686"):
# CentOS 7 w/ glibc 2.17 (PEP 599)
map_glibc_to_manylinux = {(2, 17): "manylinux2014"}
if arch in {"x86_64", "i686"}:
# CentOS 6 w/ glibc 2.12 (PEP 571)
map_glibc_to_manylinux[(2, 12)] = "manylinux2010"
# CentOS 5 w/ glibc 2.5 (PEP 513)
map_glibc_to_manylinux[(2, 5)] = "manylinux1"
# glibc in manylinux1 is 2.5
min_minor = 5
min_minor = 4
else:
# glibc in manylinux2014 is 2.5
min_minor = 17
# glibc in manylinux2014 is 2.17
min_minor = 16
cur_glibc = _get_glibc_version()
for glibc_minor in range(min_minor, cur_glibc[1]):
for glibc_minor in range(cur_glibc[1], min_minor, -1):
if _have_compatible_glibc(2, glibc_minor):
pep600_support.append(
(
"manylinux_2_{}_{}".format(glibc_minor, arch),
(2, glibc_minor),
)
manylinux_support.append(
("manylinux_2_{}".format(glibc_minor), (2, glibc_minor))
)
if (2, glibc_minor) in map_glibc_to_manylinux:
manylinux_support.append(
(map_glibc_to_manylinux[(2, glibc_minor)], (2, glibc_minor))
)
else:
# no need to keep incrementing
break
if arch in {"x86_64", "i686"}:
manylinux_support.append(
("manylinux2010", (2, 12))
) # CentOS 6 w/ glibc 2.12 (PEP 571)
manylinux_support.append(
("manylinux1", (2, 5))
) # CentOS 5 w/ glibc 2.5 (PEP 513)
manylinux_support_iter = iter(manylinux_support)
for name, glibc_version in manylinux_support_iter:
if _is_manylinux_compatible(name, glibc_version):
yield linux.replace("linux", name)
break
# Support for a later manylinux implies support for an earlier version.
for name, _ in manylinux_support_iter:
yield linux.replace("linux", name)
for name, glibc_verison in iter(pep600_support):
if _is_manylinux_compatible(name, glibc_version):
yield name
yield linux


Expand Down
45 changes: 44 additions & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ def test_glibc_version_string_confstr(self, monkeypatch):
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
assert tags._glibc_version_string_confstr() == "2.20"

def test_glibc_version_string_fail(self, monkeypatch):
monkeypatch.setattr(os, "confstr", lambda x: None, raising=False)
monkeypatch.setitem(sys.modules, "ctypes", None)
assert tags._glibc_version_string() is None
assert tags._have_compatible_glibc(2, 5) is False
assert tags._get_glibc_version() == (-1, -1)

@pytest.mark.parametrize(
"failure",
[pretend.raiser(ValueError), pretend.raiser(OSError), lambda x: "XXX"],
Expand Down Expand Up @@ -463,7 +470,18 @@ def test_linux_platforms_manylinux2010(self, is_x86, monkeypatch):
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
platforms = list(tags._linux_platforms(is_32bit=False))
arch = platform.machine()
expected = ["manylinux2010_" + arch, "manylinux1_" + arch, "linux_" + arch]
expected = [
"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,
]
assert platforms == expected

def test_linux_platforms_manylinux2014(self, is_x86, monkeypatch):
Expand All @@ -477,7 +495,19 @@ def test_linux_platforms_manylinux2014(self, is_x86, monkeypatch):
arch = platform.machine()
expected = [
"manylinux2014_" + arch,
"manylinux_2_16_" + arch,
"manylinux_2_15_" + arch,
"manylinux_2_14_" + arch,
"manylinux_2_13_" + arch,
"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,
]
Expand Down Expand Up @@ -511,8 +541,21 @@ def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch):
)
platforms = list(tags._linux_platforms(is_32bit=True))
expected = [
# "manylinux_2_17_i686", # rejected since it comes before maylinux2014
"manylinux2014_i686",
"manylinux_2_16_i686",
"manylinux_2_15_i686",
"manylinux_2_14_i686",
"manylinux_2_13_i686",
"manylinux_2_12_i686",
"manylinux2010_i686",
"manylinux_2_11_i686",
"manylinux_2_10_i686",
"manylinux_2_9_i686",
"manylinux_2_8_i686",
"manylinux_2_7_i686",
"manylinux_2_6_i686",
"manylinux_2_5_i686",
"manylinux1_i686",
"linux_i686",
]
Expand Down

0 comments on commit f432bcd

Please sign in to comment.