Skip to content

Commit 538d9f5

Browse files
committed
refactor for _manylinux module changes
1 parent e75015c commit 538d9f5

File tree

2 files changed

+180
-100
lines changed

2 files changed

+180
-100
lines changed

packaging/tags.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -435,19 +435,35 @@ def mac_platforms(version=None, arch=None):
435435
)
436436

437437

438-
# From PEP 513.
439-
def _is_manylinux_compatible(name, glibc_version):
440-
# type: (str, GlibcVersion) -> bool
438+
# From PEP 513, PEP 600
439+
def _is_manylinux_compatible(name, arch, glibc_version):
440+
# type: (str, str, GlibcVersion) -> bool
441+
sys_glibc = _get_glibc_version()
442+
if sys_glibc < glibc_version:
443+
return False
441444
# Check for presence of _manylinux module.
442445
try:
443446
import _manylinux # noqa
444-
445-
return bool(getattr(_manylinux, name + "_compatible"))
446-
except (ImportError, AttributeError):
447-
# Fall through to heuristic check below.
447+
except ImportError:
448448
pass
449-
450-
return _have_compatible_glibc(*glibc_version)
449+
else:
450+
if hasattr(_manylinux, "manylinux_compatible"):
451+
result = _manylinux.manylinux_compatible(
452+
glibc_version[0], glibc_version[1], arch
453+
)
454+
if result is not None:
455+
return bool(result)
456+
else:
457+
if glibc_version == (2, 5):
458+
if hasattr(_manylinux, "manylinux1_compatible"):
459+
return bool(_manylinux.manylinux1_compatible)
460+
if glibc_version == (2, 12):
461+
if hasattr(_manylinux, "manylinux2010_compatible"):
462+
return bool(_manylinux.manylinux2010_compatible)
463+
if glibc_version == (2, 17):
464+
if hasattr(_manylinux, "manylinux2014_compatible"):
465+
return bool(_manylinux.manylinux2014_compatible)
466+
return True
451467

452468

453469
def _glibc_version_string():
@@ -512,14 +528,6 @@ def _glibc_version_string_ctypes():
512528
return version_str
513529

514530

515-
# Separated out from have_compatible_glibc for easier unit testing.
516-
def _check_glibc_version(version_str, tag_major, tag_minor):
517-
# type: (str, int, int) -> bool
518-
# Check against requested version.
519-
sys_major, sys_minor = _parse_glibc_version(version_str)
520-
return (sys_major, sys_minor) >= (tag_major, tag_minor)
521-
522-
523531
def _parse_glibc_version(version_str):
524532
# type: (str) -> Tuple[int, int]
525533
# Parse glibc version
@@ -539,20 +547,19 @@ def _parse_glibc_version(version_str):
539547
return (int(m.group("major")), int(m.group("minor")))
540548

541549

542-
def _have_compatible_glibc(tag_major, tag_minor):
543-
# type: (int, int) -> bool
544-
version_str = _glibc_version_string()
545-
if version_str is None:
546-
return False
547-
return _check_glibc_version(version_str, tag_major, tag_minor)
550+
_glibc_version = [] # type: List[Tuple[int, int]]
548551

549552

550553
def _get_glibc_version():
551554
# type: () -> Tuple[int, int]
555+
if _glibc_version:
556+
return _glibc_version[0]
552557
version_str = _glibc_version_string()
553558
if version_str is None:
554-
return -1, -1
555-
return _parse_glibc_version(version_str)
559+
_glibc_version.append((-1, -1))
560+
else:
561+
_glibc_version.append(_parse_glibc_version(version_str))
562+
return _glibc_version[0]
556563

557564

558565
# Python does not provide platform information at sufficient granularity to
@@ -681,7 +688,6 @@ def _manylinux_tags(linux, arch):
681688
# On x86/i686 also oldest glibc to be supported is (2, 5).
682689
too_old_glibc2 = glibcVersion(2, 4)
683690
current_glibc = glibcVersion(*_get_glibc_version())
684-
is_compat = False
685691
glibc_max_list = [current_glibc]
686692
# We can assume compatibility across glibc major versions.
687693
# https://sourceware.org/bugzilla/show_bug.cgi?id=24636
@@ -700,18 +706,12 @@ def _manylinux_tags(linux, arch):
700706
for glibc_minor in range(glibc_max.minor, min_minor, -1):
701707
glibc_version = (glibc_max.major, glibc_minor)
702708
tag = "manylinux_{}_{}".format(*glibc_version)
703-
# Once _is_manylinux_compatible() is True, it is True for any
704-
# lower manylinux tag for this glibc major version.
705-
is_compat = is_compat or _is_manylinux_compatible(tag, glibc_version)
706-
if is_compat:
709+
if _is_manylinux_compatible(tag, arch, glibc_version):
707710
yield linux.replace("linux", tag)
708-
# Handle the manylinux1, manylinux2010, manylinux2014 tags.
711+
# Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
709712
if glibc_version in _LEGACY_MANYLINUX_MAP:
710713
legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
711-
is_compat = is_compat or _is_manylinux_compatible(
712-
legacy_tag, glibc_version
713-
)
714-
if is_compat:
714+
if _is_manylinux_compatible(legacy_tag, arch, glibc_version):
715715
yield linux.replace("linux", legacy_tag)
716716

717717

0 commit comments

Comments
 (0)