-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Fix get_preferred_scheme detection for CPython 3.10 alpha #10252
Conversation
Support for the feature sysconfig.get_preferred_scheme (added on Python 3.10 - see bpo-43312) was checked based on the Python version (see commit ca4aa12 "Use Python 3.10 sysconfig.get_preferred_scheme()"). Unfortunately, this API seems to be introduced with the 3.10.beta Cpython builds and does not seem to be part of the 3.10.alpha versions. Hence, on these versions, pip fails with exception: AttributeError: module 'sysconfig' has no attribute 'get_preferred_scheme' The solution chosen is to check if the function exists in the sysconfig module using introspection instead of relying on Python versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, please add a NEWS entry
@@ -24,7 +24,7 @@ | |||
|
|||
_AVAILABLE_SCHEMES = set(sysconfig.get_scheme_names()) | |||
|
|||
_HAS_PREFERRED_SCHEME_API = sys.version_info >= (3, 10) | |||
_HAS_PREFERRED_SCHEME_API = 'get_preferred_scheme' in dir(sysconfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_HAS_PREFERRED_SCHEME_API = 'get_preferred_scheme' in dir(sysconfig) | |
_HAS_PREFERRED_SCHEME_API = bool(getattr(sysconfig, "get_preferred_scheme", None)) |
Maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better still, hasattr(sysconfig, "get_preferred_scheme")
, surely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Going in the getattr direction, I decided to save the value directly instead of its boolean value to make it easier to use.
Let me know if that's fine for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, storing the function object directly makes sense, thanks!
I can see that the CI is failing because of errors: unused 'type: ignore' comment. |
I think it’s basically saying those type comments are redundant and should be removed. |
Thanks for your help @uranusjr . Do you think it'd be worth adding the 3.10 version to the Github workflow ? My suggestion would be to go for the latest alpha and the latest beta:
Or maybe just:
|
There are some issues blocking the possibility, see #10164. |
Bumps [pip](https://github.com/pypa/pip) from 21.2.2 to 21.2.3. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/pypa/pip/blob/main/NEWS.rst">pip's changelog</a>.</em></p> <blockquote> <h1>21.2.3 (2021-08-06)</h1> <h2>Bug Fixes</h2> <ul> <li>Modify the <code>sysconfig.get_preferred_scheme</code> function check to be compatible with CPython 3.10’s alphareleases. (<code>[#10252](pypa/pip#10252) <https://github.com/pypa/pip/issues/10252></code>_)</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="https://github.com/pypa/pip/commit/c2c92c7e8c05bca02cac793100a4bf43d0a1ddda"><code>c2c92c7</code></a> Bump for release</li> <li><a href="https://github.com/pypa/pip/commit/516fc4915a173b28acd276786f53edd1a6969319"><code>516fc49</code></a> Update AUTHORS.txt</li> <li><a href="https://github.com/pypa/pip/commit/a00a04475d9ac81686a757b7d4f76cda38d084df"><code>a00a044</code></a> Normalize sys.prefix for old virtualenv</li> <li><a href="https://github.com/pypa/pip/commit/00656aae146891ff1d1437e6a9105500d501f00d"><code>00656aa</code></a> Prevent returning relative paths for a location</li> <li><a href="https://github.com/pypa/pip/commit/41a844263c4d687903982f3ced14ba8e8da246f8"><code>41a8442</code></a> Use posix_prefix for Apple's system Python</li> <li><a href="https://github.com/pypa/pip/commit/3ecc39128adc8f54682a76fea20ce76209743006"><code>3ecc391</code></a> More workaround for Debian's faulty sysconfig</li> <li><a href="https://github.com/pypa/pip/commit/d8c5b7d8908aa2344981f14b1111854efa88cdf9"><code>d8c5b7d</code></a> Detect "the other" Red Hat patch for Cygwin</li> <li><a href="https://github.com/pypa/pip/commit/c5332d5ac9f4226c67f840e2f40e09cfe875c989"><code>c5332d5</code></a> Remove extra period in deprecation message</li> <li><a href="https://github.com/pypa/pip/commit/1ac90bbda73dc7e4dceeed29d4f2302e1ce991a5"><code>1ac90bb</code></a> Fix get_preferred_scheme detection for CPython 3.10 alpha</li> <li>See full diff in <a href="https://github.com/pypa/pip/compare/21.2.2...21.2.3">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=pip&package-manager=pip&previous-version=21.2.2&new-version=21.2.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details>
And update pip hoping to fix pypa/pip#10252
Support for the feature sysconfig.get_preferred_scheme
(added on Python 3.10 - see bpo-43312) was checked based
on the Python version (see commit
ca4aa12
"Use Python 3.10 sysconfig.get_preferred_scheme()").
Unfortunately, this API seems to be introduced with the
3.10.beta Cpython builds and does not seem to be part of
the 3.10.alpha versions.
Hence, on these versions, pip fails with exception:
AttributeError: module 'sysconfig' has no attribute 'get_preferred_scheme'
The solution chosen is to check if the function exists
in the sysconfig module using introspection instead of
relying on Python versions.