Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
pip._internal.utils.glibc_version_string() can use os.confstr('CS_GNU_LIBC_VERSION') to avoid ctypes #6675
Currently, the pip._internal.utils.glibc_version_string() function is implemented with ctypes to access gnu_get_libc_version() function. But os.confstr('CS_GNU_LIBC_VERSION') could be used instead to avoid ctypes.
I recently modified platform.libc_ver() on Python stdlib to use os.confstr('CS_GNU_LIBC_VERSION') is available:
if executable is None: try: ver = os.confstr('CS_GNU_LIBC_VERSION') # parse 'glibc 2.28' as ('glibc', '2.28') parts = ver.split(maxsplit=1) if len(parts) == 2: return tuple(parts) except (AttributeError, ValueError, OSError): # os.confstr() or CS_GNU_LIBC_VERSION value not available pass
Note: I noticed this issue when an user reported a traceback in pip when the ctypes is not available: https://email@example.com/thread/MTIRNYFAZTQQPHKAQXXREP33NYV2TW2J/
The best would be if pip could avoid completely ctypes, but I'm not sure if it's possible. In the past, I reported issues times to times when pip broke when ctypes was not available, but it seems to be a lost battle: pip or pip dependencies commonly use ctypes. Instead, on the Python upstream CI, we now try to ensure that ctypes is always available on buildbots.
If you want to test a Python without ctypes, inject this code before using pip: