Skip to content

Commit 59231fe

Browse files
committed
reverse order, add test for coverage
1 parent 7e81d5d commit 59231fe

File tree

2 files changed

+64
-26
lines changed

2 files changed

+64
-26
lines changed

packaging/tags.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -664,48 +664,43 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
664664
linux = "linux_armv7l"
665665
manylinux_support = []
666666
_, arch = linux.split("_", 1)
667-
pep600_support = []
668667
if _have_compatible_manylinux_abi(arch):
669668
if arch in {"x86_64", "i686", "aarch64", "armv7l", "ppc64", "ppc64le", "s390x"}:
670-
manylinux_support.append(
671-
("manylinux2014", (2, 17))
672-
) # CentOS 7 w/ glibc 2.17 (PEP 599)
673-
if arch in ("x86_64", "i686"):
669+
# CentOS 7 w/ glibc 2.17 (PEP 599)
670+
map_glibc_to_manylinux = {(2, 17): 'manylinux2014'}
671+
if arch in {"x86_64", "i686"}:
672+
# CentOS 6 w/ glibc 2.12 (PEP 571)
673+
map_glibc_to_manylinux[(2, 12)] = "manylinux2010"
674+
# CentOS 5 w/ glibc 2.5 (PEP 513)
675+
map_glibc_to_manylinux[(2, 5)] = "manylinux1"
674676
# glibc in manylinux1 is 2.5
675-
min_minor = 5
677+
min_minor = 4
676678
else:
677-
# glibc in manylinux2014 is 2.5
678-
min_minor = 17
679+
# glibc in manylinux2014 is 2.17
680+
min_minor = 16
679681
cur_glibc = _get_glibc_version()
680-
for glibc_minor in range(min_minor, cur_glibc[1]):
682+
for glibc_minor in range(cur_glibc[1], min_minor, -1):
681683
if _have_compatible_glibc(2, glibc_minor):
682-
pep600_support.append(
684+
manylinux_support.append(
683685
(
684-
"manylinux_2_{}_{}".format(glibc_minor, arch),
686+
"manylinux_2_{}".format(glibc_minor),
687+
(2, glibc_minor),
688+
)
689+
)
690+
if (2, glibc_minor) in map_glibc_to_manylinux:
691+
manylinux_support.append(
692+
(
693+
map_glibc_to_manylinux[(2, glibc_minor)],
685694
(2, glibc_minor),
686695
)
687696
)
688-
else:
689-
# no need to keep incrementing
690-
break
691-
if arch in {"x86_64", "i686"}:
692-
manylinux_support.append(
693-
("manylinux2010", (2, 12))
694-
) # CentOS 6 w/ glibc 2.12 (PEP 571)
695-
manylinux_support.append(
696-
("manylinux1", (2, 5))
697-
) # CentOS 5 w/ glibc 2.5 (PEP 513)
698697
manylinux_support_iter = iter(manylinux_support)
699698
for name, glibc_version in manylinux_support_iter:
700699
if _is_manylinux_compatible(name, glibc_version):
701700
yield linux.replace("linux", name)
702701
break
703-
# Support for a later manylinux implies support for an earlier version.
704702
for name, _ in manylinux_support_iter:
705703
yield linux.replace("linux", name)
706-
for name, glibc_verison in iter(pep600_support):
707-
if _is_manylinux_compatible(name, glibc_version):
708-
yield name
709704
yield linux
710705

711706

tests/test_tags.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,13 @@ def test_glibc_version_string_confstr(self, monkeypatch):
373373
monkeypatch.setattr(os, "confstr", lambda x: "glibc 2.20", raising=False)
374374
assert tags._glibc_version_string_confstr() == "2.20"
375375

376+
def test_glibc_version_string_fail(self, monkeypatch):
377+
monkeypatch.setattr(os, "confstr", lambda x: None, raising=False)
378+
monkeypatch.setitem(sys.modules, "ctypes", None)
379+
assert tags._glibc_version_string() is None
380+
assert tags._have_compatible_glibc(2, 5) is False
381+
assert tags._get_glibc_version() == (-1, -1)
382+
376383
@pytest.mark.parametrize(
377384
"failure",
378385
[pretend.raiser(ValueError), pretend.raiser(OSError), lambda x: "XXX"],
@@ -463,7 +470,18 @@ def test_linux_platforms_manylinux2010(self, is_x86, monkeypatch):
463470
monkeypatch.setattr(platform, "machine", lambda: "x86_64")
464471
platforms = list(tags._linux_platforms(is_32bit=False))
465472
arch = platform.machine()
466-
expected = ["manylinux2010_" + arch, "manylinux1_" + arch, "linux_" + arch]
473+
expected = [
474+
"manylinux2010_" + arch,
475+
"manylinux_2_11_" + arch,
476+
"manylinux_2_10_" + arch,
477+
"manylinux_2_9_" + arch,
478+
"manylinux_2_8_" + arch,
479+
"manylinux_2_7_" + arch,
480+
"manylinux_2_6_" + arch,
481+
"manylinux_2_5_" + arch,
482+
"manylinux1_" + arch,
483+
"linux_" + arch,
484+
]
467485
assert platforms == expected
468486

469487
def test_linux_platforms_manylinux2014(self, is_x86, monkeypatch):
@@ -477,7 +495,19 @@ def test_linux_platforms_manylinux2014(self, is_x86, monkeypatch):
477495
arch = platform.machine()
478496
expected = [
479497
"manylinux2014_" + arch,
498+
"manylinux_2_16_" + arch,
499+
"manylinux_2_15_" + arch,
500+
"manylinux_2_14_" + arch,
501+
"manylinux_2_13_" + arch,
502+
"manylinux_2_12_" + arch,
480503
"manylinux2010_" + arch,
504+
"manylinux_2_11_" + arch,
505+
"manylinux_2_10_" + arch,
506+
"manylinux_2_9_" + arch,
507+
"manylinux_2_8_" + arch,
508+
"manylinux_2_7_" + arch,
509+
"manylinux_2_6_" + arch,
510+
"manylinux_2_5_" + arch,
481511
"manylinux1_" + arch,
482512
"linux_" + arch,
483513
]
@@ -511,8 +541,21 @@ def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch):
511541
)
512542
platforms = list(tags._linux_platforms(is_32bit=True))
513543
expected = [
544+
# "manylinux_2_17_i686", # rejected since it comes before maylinux2014
514545
"manylinux2014_i686",
546+
"manylinux_2_16_i686",
547+
"manylinux_2_15_i686",
548+
"manylinux_2_14_i686",
549+
"manylinux_2_13_i686",
550+
"manylinux_2_12_i686",
515551
"manylinux2010_i686",
552+
"manylinux_2_11_i686",
553+
"manylinux_2_10_i686",
554+
"manylinux_2_9_i686",
555+
"manylinux_2_8_i686",
556+
"manylinux_2_7_i686",
557+
"manylinux_2_6_i686",
558+
"manylinux_2_5_i686",
516559
"manylinux1_i686",
517560
"linux_i686",
518561
]

0 commit comments

Comments
 (0)