From c7b2582dd5c7abea5dd917255be5530dc2cedd57 Mon Sep 17 00:00:00 2001 From: mattip Date: Sun, 19 Apr 2020 22:39:47 +0300 Subject: [PATCH] review fixes: support glibc major version > 2 and use _LEGACY_MANYLINUX_MAP --- packaging/tags.py | 86 +++++++++++++++++++++++++--------------------- tests/test_tags.py | 2 +- 2 files changed, 48 insertions(+), 40 deletions(-) diff --git a/packaging/tags.py b/packaging/tags.py index 58463a62..c50cc3f2 100644 --- a/packaging/tags.py +++ b/packaging/tags.py @@ -57,6 +57,16 @@ _32_BIT_INTERPRETER = sys.maxsize <= 2 ** 32 +_LEGACY_MANYLINUX_MAP = { + # CentOS 7 w/ glibc 2.17 (PEP 599) + (2, 17): "manylinux2014", + # CentOS 6 w/ glibc 2.12 (PEP 571) + (2, 12): "manylinux2010", + # CentOS 5 w/ glibc 2.5 (PEP 513) + (2, 5): "manylinux1", +} + + class Tag(object): """ A representation of the tag triple for a wheel. @@ -494,11 +504,11 @@ def _glibc_version_string_ctypes(): # Separated out from have_compatible_glibc for easier unit testing. -def _check_glibc_version(version_str, required_major, minimum_minor): +def _check_glibc_version(version_str, tag_major, tag_minor): # type: (str, int, int) -> bool # Check against requested version. - major, minor = _parse_glibc_version(version_str) - return major == required_major and minor >= minimum_minor + sys_major, sys_minor = _parse_glibc_version(version_str) + return (sys_major, sys_minor) >= (tag_major, tag_minor) def _parse_glibc_version(version_str): @@ -516,16 +526,16 @@ def _parse_glibc_version(version_str): " got: %s" % version_str, RuntimeWarning, ) - return (-1, -1) + return -1, -1 return (int(m.group("major")), int(m.group("minor"))) -def _have_compatible_glibc(required_major, minimum_minor): +def _have_compatible_glibc(tag_major, tag_minor): # type: (int, int) -> bool version_str = _glibc_version_string() if version_str is None: return False - return _check_glibc_version(version_str, required_major, minimum_minor) + return _check_glibc_version(version_str, tag_major, tag_minor) def _get_glibc_version(): @@ -651,7 +661,7 @@ def _have_compatible_manylinux_abi(arch): return _is_linux_armhf() if arch == "i686": return _is_linux_i686() - return True + return arch in {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x"} def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): @@ -664,38 +674,36 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): linux = "linux_armv7l" _, arch = linux.split("_", 1) if _have_compatible_manylinux_abi(arch): - map_glibc_to_manylinux = {} - # glibc in manylinux2014 is 2.17 - min_minor = 16 - if arch in {"x86_64", "i686", "aarch64", "armv7l", "ppc64", "ppc64le", "s390x"}: - # 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 = 4 - cur_glibc = _get_glibc_version() - manylinux_compat = False - for glibc_minor in range(cur_glibc[1], min_minor, -1): - plat = "manylinux_2_{}".format(glibc_minor) - # Once _is_manylinux_compatible() is True, it is True for any - # lower manylinux tag. - manylinux_compat = manylinux_compat or _is_manylinux_compatible( - plat, (2, glibc_minor) - ) - if manylinux_compat: - yield linux.replace("linux", plat) - # Handle the manylinux1, manylinux2010, manylinux2014 tags - if (2, glibc_minor) in map_glibc_to_manylinux: - plat = map_glibc_to_manylinux[(2, glibc_minor)] - manylinux_compat = manylinux_compat or _is_manylinux_compatible( - plat, (2, glibc_minor) - ) - if manylinux_compat: - yield linux.replace("linux", plat) + # Oldest glibc to be supported is (2, 17) ( + too_old_glibc = (2, 16) + if arch in {"x86_64", "i686"}: + # glibc in manylinux1 is 2.5, which is the oldest + # that will be supported + too_old_glibc = (2, 4) + current_glibc = _get_glibc_version() + is_compat = False + for glibc_major in range(current_glibc[0], 1, -1): + if glibc_major == too_old_glibc[0]: + min_minor = too_old_glibc[1] + else: + # oldest supported minor version is 0 + min_minor = -1 + for glibc_minor in range(current_glibc[1], min_minor, -1): + glibc_version = (glibc_major, glibc_minor) + tag = "manylinux_{}_{}".format(*glibc_version) + # Once _is_manylinux_compatible() is True, it is True for any + # lower manylinux tag. + is_compat = is_compat or _is_manylinux_compatible(tag, glibc_version) + if is_compat: + yield linux.replace("linux", tag) + # Handle the manylinux1, manylinux2010, manylinux2014 tags. + if glibc_version in _LEGACY_MANYLINUX_MAP: + legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version] + is_compat = is_compat or _is_manylinux_compatible( + legacy_tag, glibc_version + ) + if is_compat: + yield linux.replace("linux", legacy_tag) yield linux diff --git a/tests/test_tags.py b/tests/test_tags.py index cd098deb..0a8bb915 100644 --- a/tests/test_tags.py +++ b/tests/test_tags.py @@ -326,7 +326,7 @@ def test_is_manylinux_compatible_glibc_support( ("2.4", 2, 4, True), ("2.4", 2, 5, False), ("2.4", 2, 3, True), - ("3.4", 2, 4, False), + ("3.4", 2, 4, True), ], ) def test_check_glibc_version(self, version_str, major, minor, expected):