Skip to content

Commit

Permalink
review fixes: support glibc major version > 2 and use _LEGACY_MANYLIN…
Browse files Browse the repository at this point in the history
…UX_MAP
  • Loading branch information
mattip committed Apr 19, 2020
1 parent a6754b0 commit c7b2582
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 40 deletions.
86 changes: 47 additions & 39 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand All @@ -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():
Expand Down Expand Up @@ -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):
Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit c7b2582

Please sign in to comment.