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

Fix get_preferred_scheme detection for CPython 3.10 alpha #10252

Merged
merged 5 commits into from
Aug 1, 2021
Merged

Fix get_preferred_scheme detection for CPython 3.10 alpha #10252

merged 5 commits into from
Aug 1, 2021

Conversation

SylvainDe
Copy link
Contributor

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.

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.
Copy link
Member

@uranusjr uranusjr left a 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_HAS_PREFERRED_SCHEME_API = 'get_preferred_scheme' in dir(sysconfig)
_HAS_PREFERRED_SCHEME_API = bool(getattr(sysconfig, "get_preferred_scheme", None))

Maybe?

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pfmoore hasattr was definitly the proper way to do, I do not know what I originally had in mind.
@uranusjr I've updated the PR to use getattr, let me know if hasattr is a preferred option.

@SylvainDe SylvainDe requested a review from uranusjr August 1, 2021 06:54
Copy link
Member

@uranusjr uranusjr left a 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!

@SylvainDe
Copy link
Contributor Author

I can see that the CI is failing because of errors: unused 'type: ignore' comment.
I'll have a look into it but I've never used type comments. Any suggestion is welcome.

@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2021

I think it’s basically saying those type comments are redundant and should be removed.

news/10252.bugfix.rst Outdated Show resolved Hide resolved
news/10252.bugfix.rst Outdated Show resolved Hide resolved
@uranusjr uranusjr changed the title Check support of sysconfig.get_preferred_scheme() in a different way Fix get_preferred_scheme detection for CPython 3.10 alpha Aug 1, 2021
@uranusjr uranusjr merged commit 87aee20 into pypa:main Aug 1, 2021
@uranusjr uranusjr added this to the 21.2.3 milestone Aug 1, 2021
@SylvainDe
Copy link
Contributor Author

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:

  • 3.10.0-alpha.7
  • 3.10.0-beta.4

Or maybe just:

  • 3.10-dev (which I'd expect to correspond to 3.10.0-a0)

@uranusjr
Copy link
Member

uranusjr commented Aug 1, 2021

There are some issues blocking the possibility, see #10164.

@uranusjr uranusjr mentioned this pull request Aug 6, 2021
inmantaci pushed a commit to inmanta/inmanta-core that referenced this pull request Aug 6, 2021
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) &lt;https://github.com/pypa/pip/issues/10252&gt;</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 &quot;the other&quot; 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>
macbre added a commit to macbre/index-digest that referenced this pull request Aug 9, 2021
And update pip hoping to fix pypa/pip#10252
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants