@@ -435,19 +435,35 @@ def mac_platforms(version=None, arch=None):
435
435
)
436
436
437
437
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
441
444
# Check for presence of _manylinux module.
442
445
try :
443
446
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 :
448
448
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
451
467
452
468
453
469
def _glibc_version_string ():
@@ -512,14 +528,6 @@ def _glibc_version_string_ctypes():
512
528
return version_str
513
529
514
530
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
-
523
531
def _parse_glibc_version (version_str ):
524
532
# type: (str) -> Tuple[int, int]
525
533
# Parse glibc version
@@ -539,20 +547,19 @@ def _parse_glibc_version(version_str):
539
547
return (int (m .group ("major" )), int (m .group ("minor" )))
540
548
541
549
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]]
548
551
549
552
550
553
def _get_glibc_version ():
551
554
# type: () -> Tuple[int, int]
555
+ if _glibc_version :
556
+ return _glibc_version [0 ]
552
557
version_str = _glibc_version_string ()
553
558
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 ]
556
563
557
564
558
565
# Python does not provide platform information at sufficient granularity to
@@ -681,7 +688,6 @@ def _manylinux_tags(linux, arch):
681
688
# On x86/i686 also oldest glibc to be supported is (2, 5).
682
689
too_old_glibc2 = glibcVersion (2 , 4 )
683
690
current_glibc = glibcVersion (* _get_glibc_version ())
684
- is_compat = False
685
691
glibc_max_list = [current_glibc ]
686
692
# We can assume compatibility across glibc major versions.
687
693
# https://sourceware.org/bugzilla/show_bug.cgi?id=24636
@@ -700,18 +706,12 @@ def _manylinux_tags(linux, arch):
700
706
for glibc_minor in range (glibc_max .minor , min_minor , - 1 ):
701
707
glibc_version = (glibc_max .major , glibc_minor )
702
708
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 ):
707
710
yield linux .replace ("linux" , tag )
708
- # Handle the manylinux1, manylinux2010, manylinux2014 tags.
711
+ # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
709
712
if glibc_version in _LEGACY_MANYLINUX_MAP :
710
713
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 ):
715
715
yield linux .replace ("linux" , legacy_tag )
716
716
717
717
0 commit comments