Skip to content

Commit 3e8aa45

Browse files
committed
review fixes: support glibc major version > 2 and use _LEGACY_MANYLINUX_MAP
1 parent a6754b0 commit 3e8aa45

File tree

2 files changed

+63
-38
lines changed

2 files changed

+63
-38
lines changed

packaging/tags.py

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@
5757
_32_BIT_INTERPRETER = sys.maxsize <= 2 ** 32
5858

5959

60+
_LEGACY_MANYLINUX_MAP = {
61+
# CentOS 7 w/ glibc 2.17 (PEP 599)
62+
(2, 17): "manylinux2014",
63+
# CentOS 6 w/ glibc 2.12 (PEP 571)
64+
(2, 12): "manylinux2010",
65+
# CentOS 5 w/ glibc 2.5 (PEP 513)
66+
(2, 5): "manylinux1",
67+
}
68+
69+
6070
class Tag(object):
6171
"""
6272
A representation of the tag triple for a wheel.
@@ -494,11 +504,11 @@ def _glibc_version_string_ctypes():
494504

495505

496506
# Separated out from have_compatible_glibc for easier unit testing.
497-
def _check_glibc_version(version_str, required_major, minimum_minor):
507+
def _check_glibc_version(version_str, tag_major, tag_minor):
498508
# type: (str, int, int) -> bool
499509
# Check against requested version.
500-
major, minor = _parse_glibc_version(version_str)
501-
return major == required_major and minor >= minimum_minor
510+
sys_major, sys_minor = _parse_glibc_version(version_str)
511+
return (sys_major, sys_minor) >= (tag_major, tag_minor)
502512

503513

504514
def _parse_glibc_version(version_str):
@@ -516,16 +526,16 @@ def _parse_glibc_version(version_str):
516526
" got: %s" % version_str,
517527
RuntimeWarning,
518528
)
519-
return (-1, -1)
529+
return -1, -1
520530
return (int(m.group("major")), int(m.group("minor")))
521531

522532

523-
def _have_compatible_glibc(required_major, minimum_minor):
533+
def _have_compatible_glibc(tag_major, tag_minor):
524534
# type: (int, int) -> bool
525535
version_str = _glibc_version_string()
526536
if version_str is None:
527537
return False
528-
return _check_glibc_version(version_str, required_major, minimum_minor)
538+
return _check_glibc_version(version_str, tag_major, tag_minor)
529539

530540

531541
def _get_glibc_version():
@@ -651,7 +661,7 @@ def _have_compatible_manylinux_abi(arch):
651661
return _is_linux_armhf()
652662
if arch == "i686":
653663
return _is_linux_i686()
654-
return True
664+
return arch in {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x"}
655665

656666

657667
def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
@@ -664,38 +674,34 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
664674
linux = "linux_armv7l"
665675
_, arch = linux.split("_", 1)
666676
if _have_compatible_manylinux_abi(arch):
667-
map_glibc_to_manylinux = {}
668-
# glibc in manylinux2014 is 2.17
669-
min_minor = 16
670-
if arch in {"x86_64", "i686", "aarch64", "armv7l", "ppc64", "ppc64le", "s390x"}:
671-
# CentOS 7 w/ glibc 2.17 (PEP 599)
672-
map_glibc_to_manylinux[(2, 17)] = "manylinux2014"
673-
if arch in {"x86_64", "i686"}:
674-
# CentOS 6 w/ glibc 2.12 (PEP 571)
675-
map_glibc_to_manylinux[(2, 12)] = "manylinux2010"
676-
# CentOS 5 w/ glibc 2.5 (PEP 513)
677-
map_glibc_to_manylinux[(2, 5)] = "manylinux1"
678-
# glibc in manylinux1 is 2.5
679-
min_minor = 4
680-
cur_glibc = _get_glibc_version()
681-
manylinux_compat = False
682-
for glibc_minor in range(cur_glibc[1], min_minor, -1):
683-
plat = "manylinux_2_{}".format(glibc_minor)
677+
# Oldest glibc to be supported is (2, 17).
678+
too_old_glibc = (2, 16)
679+
if arch in {"x86_64", "i686"}:
680+
# On x86/i686 also oldest glibc to be supported is (2, 5).
681+
too_old_glibc = (2, 4)
682+
current_glibc = _get_glibc_version()
683+
is_compat = False
684+
if current_glibc[0] == too_old_glibc[0]:
685+
min_minor = too_old_glibc[1]
686+
else:
687+
# For glibc major version x>2, oldest supported is (x, 0).
688+
min_minor = -1
689+
for glibc_minor in range(current_glibc[1], min_minor, -1):
690+
glibc_version = (current_glibc[0], glibc_minor)
691+
tag = "manylinux_{}_{}".format(*glibc_version)
684692
# Once _is_manylinux_compatible() is True, it is True for any
685-
# lower manylinux tag.
686-
manylinux_compat = manylinux_compat or _is_manylinux_compatible(
687-
plat, (2, glibc_minor)
688-
)
689-
if manylinux_compat:
690-
yield linux.replace("linux", plat)
691-
# Handle the manylinux1, manylinux2010, manylinux2014 tags
692-
if (2, glibc_minor) in map_glibc_to_manylinux:
693-
plat = map_glibc_to_manylinux[(2, glibc_minor)]
694-
manylinux_compat = manylinux_compat or _is_manylinux_compatible(
695-
plat, (2, glibc_minor)
693+
# lower manylinux tag for this glibc major version.
694+
is_compat = is_compat or _is_manylinux_compatible(tag, glibc_version)
695+
if is_compat:
696+
yield linux.replace("linux", tag)
697+
# Handle the manylinux1, manylinux2010, manylinux2014 tags.
698+
if glibc_version in _LEGACY_MANYLINUX_MAP:
699+
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
700+
is_compat = is_compat or _is_manylinux_compatible(
701+
legacy_tag, glibc_version
696702
)
697-
if manylinux_compat:
698-
yield linux.replace("linux", plat)
703+
if is_compat:
704+
yield linux.replace("linux", legacy_tag)
699705
yield linux
700706

701707

tests/test_tags.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ def test_is_manylinux_compatible_glibc_support(
326326
("2.4", 2, 4, True),
327327
("2.4", 2, 5, False),
328328
("2.4", 2, 3, True),
329-
("3.4", 2, 4, False),
329+
("3.4", 2, 4, True),
330330
],
331331
)
332332
def test_check_glibc_version(self, version_str, major, minor, expected):
@@ -566,6 +566,25 @@ def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch):
566566
]
567567
assert platforms == expected
568568

569+
def test_linux_platforms_manylinux_glibc3(self, monkeypatch):
570+
# test for a future glic 3.x version
571+
monkeypatch.setattr(tags, "_glibc_version_string", lambda: "3.2")
572+
monkeypatch.setattr(tags, "_is_manylinux_compatible", lambda name, _: True)
573+
monkeypatch.setattr(distutils.util, "get_platform", lambda: "linux_aarch64")
574+
monkeypatch.setattr(
575+
sys,
576+
"executable",
577+
os.path.join(os.path.dirname(__file__), "hello-world-aarch64"),
578+
)
579+
platforms = list(tags._linux_platforms())
580+
expected = [
581+
"manylinux_3_2_aarch64",
582+
"manylinux_3_1_aarch64",
583+
"manylinux_3_0_aarch64",
584+
"linux_aarch64",
585+
]
586+
assert platforms == expected
587+
569588
def test_linux_platforms_manylinux2014_armv6l(self, monkeypatch):
570589
monkeypatch.setattr(
571590
tags, "_is_manylinux_compatible", lambda name, _: name == "manylinux2014"

0 commit comments

Comments
 (0)