diff options
author | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
---|---|---|
committer | Shubham Saini <shubham6405@gmail.com> | 2018-12-11 10:01:23 +0000 |
commit | 68df54d6629ec019142eb149dd037774f2d11e7c (patch) | |
tree | 345bc22d46b4e01a4ba8303b94278952a4ed2b9e /venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py |
First commit
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py')
-rw-r--r-- | venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py new file mode 100644 index 0000000..5900a10 --- /dev/null +++ b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/utils/glibc.py | |||
@@ -0,0 +1,84 @@ | |||
1 | from __future__ import absolute_import | ||
2 | |||
3 | import ctypes | ||
4 | import re | ||
5 | import warnings | ||
6 | |||
7 | |||
8 | def glibc_version_string(): | ||
9 | "Returns glibc version string, or None if not using glibc." | ||
10 | |||
11 | # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen | ||
12 | # manpage says, "If filename is NULL, then the returned handle is for the | ||
13 | # main program". This way we can let the linker do the work to figure out | ||
14 | # which libc our process is actually using. | ||
15 | process_namespace = ctypes.CDLL(None) | ||
16 | try: | ||
17 | gnu_get_libc_version = process_namespace.gnu_get_libc_version | ||
18 | except AttributeError: | ||
19 | # Symbol doesn't exist -> therefore, we are not linked to | ||
20 | # glibc. | ||
21 | return None | ||
22 | |||
23 | # Call gnu_get_libc_version, which returns a string like "2.5" | ||
24 | gnu_get_libc_version.restype = ctypes.c_char_p | ||
25 | version_str = gnu_get_libc_version() | ||
26 | # py2 / py3 compatibility: | ||
27 | if not isinstance(version_str, str): | ||
28 | version_str = version_str.decode("ascii") | ||
29 | |||
30 | return version_str | ||
31 | |||
32 | |||
33 | # Separated out from have_compatible_glibc for easier unit testing | ||
34 | def check_glibc_version(version_str, required_major, minimum_minor): | ||
35 | # Parse string and check against requested version. | ||
36 | # | ||
37 | # We use a regexp instead of str.split because we want to discard any | ||
38 | # random junk that might come after the minor version -- this might happen | ||
39 | # in patched/forked versions of glibc (e.g. Linaro's version of glibc | ||
40 | # uses version strings like "2.20-2014.11"). See gh-3588. | ||
41 | m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str) | ||
42 | if not m: | ||
43 | warnings.warn("Expected glibc version with 2 components major.minor," | ||
44 | " got: %s" % version_str, RuntimeWarning) | ||
45 | return False | ||
46 | return (int(m.group("major")) == required_major and | ||
47 | int(m.group("minor")) >= minimum_minor) | ||
48 | |||
49 | |||
50 | def have_compatible_glibc(required_major, minimum_minor): | ||
51 | version_str = glibc_version_string() | ||
52 | if version_str is None: | ||
53 | return False | ||
54 | return check_glibc_version(version_str, required_major, minimum_minor) | ||
55 | |||
56 | |||
57 | # platform.libc_ver regularly returns completely nonsensical glibc | ||
58 | # versions. E.g. on my computer, platform says: | ||
59 | # | ||
60 | # ~$ python2.7 -c 'import platform; print(platform.libc_ver())' | ||
61 | # ('glibc', '2.7') | ||
62 | # ~$ python3.5 -c 'import platform; print(platform.libc_ver())' | ||
63 | # ('glibc', '2.9') | ||
64 | # | ||
65 | # But the truth is: | ||
66 | # | ||
67 | # ~$ ldd --version | ||
68 | # ldd (Debian GLIBC 2.22-11) 2.22 | ||
69 | # | ||
70 | # This is unfortunate, because it means that the linehaul data on libc | ||
71 | # versions that was generated by pip 8.1.2 and earlier is useless and | ||
72 | # misleading. Solution: instead of using platform, use our code that actually | ||
73 | # works. | ||
74 | def libc_ver(): | ||
75 | """Try to determine the glibc version | ||
76 | |||
77 | Returns a tuple of strings (lib, version) which default to empty strings | ||
78 | in case the lookup fails. | ||
79 | """ | ||
80 | glibc_version = glibc_version_string() | ||
81 | if glibc_version is None: | ||
82 | return ("", "") | ||
83 | else: | ||
84 | return ("glibc", glibc_version) | ||