forked from pypa/manylinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanylinux-check.py
130 lines (100 loc) · 3.73 KB
/
manylinux-check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# Logic copied from PEP 513, PEP 599
import sys
def is_manylinux1_compatible():
# Only Linux, and only x86-64 / i686
from sysconfig import get_platform
if get_platform() not in ["linux-x86_64", "linux-i686"]:
return False
# Check for presence of _manylinux module
try:
import _manylinux
return bool(_manylinux.manylinux1_compatible)
except (ImportError, AttributeError):
# Fall through to heuristic check below
pass
# Check glibc version. CentOS 5 uses glibc 2.5.
return have_compatible_glibc(2, 5)
def is_manylinux2010_compatible():
# Only Linux, and only x86-64 / i686
from sysconfig import get_platform
if get_platform() not in ["linux-x86_64", "linux-i686"]:
return False
# Check for presence of _manylinux module
try:
import _manylinux
return bool(_manylinux.manylinux2010_compatible)
except (ImportError, AttributeError):
# Fall through to heuristic check below
pass
# Check glibc version. CentOS 6 uses glibc 2.12.
return have_compatible_glibc(2, 12)
def is_manylinux2014_compatible():
# Only Linux, and only supported architectures
from sysconfig import get_platform
if get_platform() not in [
"linux-x86_64",
"linux-i686",
"linux-aarch64",
"linux-armv7l",
"linux-ppc64",
"linux-ppc64le",
"linux-s390x",
"linux-riscv64",
]:
return False
# Check for presence of _manylinux module
try:
import _manylinux
return bool(_manylinux.manylinux2014_compatible)
except (ImportError, AttributeError):
# Fall through to heuristic check below
pass
# Check glibc version. CentOS 7 uses glibc 2.17.
# PEP 513 contains an implementation of this function.
return have_compatible_glibc(2, 17)
def have_compatible_glibc(major, minimum_minor):
import ctypes
process_namespace = ctypes.CDLL(None)
try:
gnu_get_libc_version = process_namespace.gnu_get_libc_version
except AttributeError:
# Symbol doesn't exist -> therefore, we are not linked to
# glibc.
return False
# Call gnu_get_libc_version, which returns a string like "2.5".
gnu_get_libc_version.restype = ctypes.c_char_p
version_str = gnu_get_libc_version()
# py2 / py3 compatibility:
if not isinstance(version_str, str):
version_str = version_str.decode("ascii")
# Parse string and check against requested version.
version = [int(piece) for piece in version_str.split(".")]
assert len(version) == 2
if major != version[0]:
return False
return minimum_minor <= version[1]
exit_code = 0
if sys.argv[2] in {"x86_64", "i686"} and (
sys.argv[1] in {"manylinux1", "manylinux2010", "manylinux2014"}
or sys.argv[1].startswith("manylinux_")
):
if is_manylinux1_compatible():
print(f"{sys.argv[1]} {sys.executable} is manylinux1 compatible")
else:
print(f"{sys.argv[1]} {sys.executable} is NOT manylinux1 compatible")
exit_code = 1
if sys.argv[2] in {"x86_64", "i686"} and (
sys.argv[1] in {"manylinux2010", "manylinux2014"} or sys.argv[1].startswith("manylinux_")
):
if is_manylinux2010_compatible():
print(f"{sys.argv[1]} {sys.executable} is manylinux2010 compatible")
else:
print(f"{sys.argv[1]} {sys.executable} is NOT manylinux2010 compatible")
exit_code = 1
if sys.argv[1] in {"manylinux2014"} or sys.argv[1].startswith("manylinux_"):
if is_manylinux2014_compatible():
print(f"{sys.argv[1]} {sys.executable} is manylinux2014 compatible")
else:
print(f"{sys.argv[1]} {sys.executable} is NOT manylinux2014 compatible")
exit_code = 1
sys.exit(exit_code)