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

pip._internal.utils.glibc_version_string() can use os.confstr('CS_GNU_LIBC_VERSION') to avoid ctypes #6675

Closed
vstinner opened this issue Jul 2, 2019 · 4 comments · Fixed by #6678
Labels
auto-locked Outdated issues that have been locked by automation help wanted For requesting inputs from other members of the community type: enhancement Improvements to functionality

Comments

@vstinner
Copy link
Contributor

vstinner commented Jul 2, 2019

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://mail.python.org/archives/list/[email protected]/thread/MTIRNYFAZTQQPHKAQXXREP33NYV2TW2J/

@triage-new-issues triage-new-issues bot added the S: needs triage Issues/PRs that need to be triaged label Jul 2, 2019
@pradyunsg pradyunsg added type: feature request Request for a new feature type: enhancement Improvements to functionality help wanted For requesting inputs from other members of the community and removed S: needs triage Issues/PRs that need to be triaged type: feature request Request for a new feature labels Jul 2, 2019
@pradyunsg
Copy link
Member

Thanks for filing this @vstinner!


If anyone wants to tackle this and file a PR, that'd be awesome!

@cjerdonek
Copy link
Member

How does this impact PR #6544 / issue #6543?

@vstinner
Copy link
Contributor Author

vstinner commented Jul 2, 2019

How does this impact PR #6544 / issue #6543?

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:

import sys
sys.modules['_ctypes'] = None
sys.modules['ctypes'] = None

@brandtbucher
Copy link
Contributor

I'm putting together a PR for this based on the usage of os.confstr above.

@lock lock bot added the auto-locked Outdated issues that have been locked by automation label Aug 20, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
auto-locked Outdated issues that have been locked by automation help wanted For requesting inputs from other members of the community type: enhancement Improvements to functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants