Skip to content

Commit

Permalink
Support PEP 600 tags
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip committed Apr 8, 2020
1 parent 9731c00 commit 372650d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
46 changes: 40 additions & 6 deletions packaging/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,14 @@ 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):
# type: (str, int, int) -> bool
# Parse string and check against requested version.
# Check against requested version.
major, minor = _parse_glibc_version(version_str)
return major == required_major and minor >= minimum_minor


def _parse_glibc_version(version_str):
# type: (str) -> Tuple[int, int]
# Parse glibc version
#
# We use a regexp instead of str.split because we want to discard any
# random junk that might come after the minor version -- this might happen
Expand All @@ -509,11 +516,8 @@ def _check_glibc_version(version_str, required_major, minimum_minor):
" got: %s" % version_str,
RuntimeWarning,
)
return False
return (
int(m.group("major")) == required_major
and int(m.group("minor")) >= minimum_minor
)
return (-1, -1)
return (int(m.group("major")), int(m.group("minor")))


def _have_compatible_glibc(required_major, minimum_minor):
Expand All @@ -524,6 +528,14 @@ def _have_compatible_glibc(required_major, minimum_minor):
return _check_glibc_version(version_str, required_major, minimum_minor)


def _get_glibc_version():
# type: () -> Tuple[int, int]
version_str = _glibc_version_string()
if version_str is None:
return -1, -1
return _parse_glibc_version(version_str)


# Python does not provide platform information at sufficient granularity to
# identify the architecture of the running executable in some cases, so we
# determine it dynamically by reading the information from the running
Expand Down Expand Up @@ -652,11 +664,30 @@ 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"):
# glibc in manylinux1 is 2.5
min_minor = 5
else:
# glibc in manylinux2014 is 2.5
min_minor = 17
cur_glibc = _get_glibc_version()
for glibc_minor in range(min_minor, cur_glibc[1]):
if _have_compatible_glibc(2, glibc_minor):
pep600_support.append(
(
"manylinux_2_{}_{}".format(glibc_minor, arch),
(2, glibc_minor),
)
)
else:
# no need to keep incrementing
break
if arch in {"x86_64", "i686"}:
manylinux_support.append(
("manylinux2010", (2, 12))
Expand All @@ -672,6 +703,9 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
# 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
2 changes: 2 additions & 0 deletions tests/test_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ def test_linux_platforms_manylinux2014(self, is_x86, monkeypatch):
assert platforms == expected

def test_linux_platforms_manylinux2014_armhf_abi(self, monkeypatch):
monkeypatch.setattr(tags, "_glibc_version_string", lambda: "2.30")
monkeypatch.setattr(
tags, "_is_manylinux_compatible", lambda name, _: name == "manylinux2014"
)
Expand All @@ -498,6 +499,7 @@ def test_linux_platforms_manylinux2014_armhf_abi(self, monkeypatch):
assert platforms == expected

def test_linux_platforms_manylinux2014_i386_abi(self, monkeypatch):
monkeypatch.setattr(tags, "_glibc_version_string", lambda: "2.20")
monkeypatch.setattr(
tags, "_is_manylinux_compatible", lambda name, _: name == "manylinux2014"
)
Expand Down

0 comments on commit 372650d

Please sign in to comment.