Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce dependency on ctypes when discovering glibc version. #6678

Merged
merged 9 commits into from Jul 21, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions news/6543.bugfix
@@ -0,0 +1 @@
If possible, the version info for glibc is extracted from ``os`` instead of ``ctypes`` (which may be missing).
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions news/6675.bugfix
@@ -0,0 +1 @@
If possible, the version info for glibc is extracted from ``os`` instead of ``ctypes`` (which may be missing).
15 changes: 14 additions & 1 deletion src/pip/_internal/utils/glibc.py
@@ -1,6 +1,6 @@
from __future__ import absolute_import

import ctypes
import os
import re
import warnings

Expand All @@ -14,6 +14,19 @@ def glibc_version_string():
# type: () -> Optional[str]
"Returns glibc version string, or None if not using glibc."

try: # https://github.com/pypa/pip/issues/6675#issue-463147612
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
glibc_version = os.confstr("CS_GNU_LIBC_VERSION").split()
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
except (AttributeError, OSError, ValueError):
pass # os.confstr() or CS_GNU_LIBC_VERSION not available...
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
else:
if len(glibc_version) == 2:
return glibc_version[-1]

try:
pradyunsg marked this conversation as resolved.
Show resolved Hide resolved
import ctypes
except ImportError:
return None

# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
# manpage says, "If filename is NULL, then the returned handle is for the
# main program". This way we can let the linker do the work to figure out
Expand Down