forked from pypa/manylinux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanylinux-check.py
120 lines (96 loc) · 3.77 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
# Logic copied from PEP 513, PEP 599
import sys
def is_manylinux1_compatible():
# Only Linux, and only x86-64 / i686
from distutils.util 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 distutils.util 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 distutils.util import get_platform
if get_platform() not in [
"linux-x86_64",
"linux-i686",
"linux-aarch64",
"linux-armv7l",
"linux-ppc64",
"linux-ppc64le",
"linux-s390x",
]:
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
if minimum_minor > version[1]:
return False
return True
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("%s %s is manylinux1 compatible" % (sys.argv[1], sys.executable))
else:
print("%s %s is NOT manylinux1 compatible" % (sys.argv[1], sys.executable))
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("%s %s is manylinux2010 compatible" % (sys.argv[1], sys.executable))
else:
print("%s %s is NOT manylinux2010 compatible" % (sys.argv[1], sys.executable))
exit_code = 1
if sys.argv[1] in {"manylinux2014"} or sys.argv[1].startswith("manylinux_"):
if is_manylinux2014_compatible():
print("%s %s is manylinux2014 compatible" % (sys.argv[1], sys.executable))
else:
print("%s %s is NOT manylinux2014 compatible" % (sys.argv[1], sys.executable))
exit_code = 1
sys.exit(exit_code)