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

Set _PYTHON_HOST_PLATFORM when building wheels in CI (Cherry-pick of #21942) #21944

Merged
merged 1 commit into from
Feb 11, 2025

Conversation

WorkerPants
Copy link
Member

This follows the lead of cibuildwheel to explicitly correctly tag our wheels on macOS, via the _PYTHON_HOST_PLATFORM environment variable. This change ensures that the pip understands which platform each wheel is built for and compatible with, and thus external plugins using pants_requirements(...) work again.

It appears the file name (including platform) tags of a wheel are derived from sysconfig.get_platform(), i.e. based on the build configuration of the current Python interpreter. Pants builds single platform wheels, so the wheels need to be tagged with the right CPU architecture.

In #21655, we changed from tagging correctly to tagging incorrectly:

  • Before that change, our self-hosted runners had 'simple' Python interpreters, built for the current platform via Pyenv. python -c 'import sysconfig; print(sysconfig.get_platform())' reports macosx-10.15-x86_64andmacosx-11.6-arm64`, and indeed the wheels were tagged like that.
  • After that change, we started using Python interpreters provided by GitHub-hosted runners. The interpreters report macosx-10.9-universal2 on both the ARM64 and x86-64 runners. That is, they're built as universal binaries that can run on either architecture. This lead to the wheels being tagged as universal2 as well.

The _PYTHON_HOST_PLATFORM environment variable overrides the default sysconfig.get_platform() value, and appears to be designed for this sort of purpose (and is used by cibuildwheel for such):

Fixes #21938

This follows the lead of `cibuildwheel` to explicitly correctly tag our
wheels on macOS, via the `_PYTHON_HOST_PLATFORM` environment variable.
This change ensures that the `pip` understands which platform each wheel
is built for and compatible with, and thus external plugins using
`pants_requirements(...)` work again.

It appears the file name (including platform) tags of a wheel are
derived from `sysconfig.get_platform()`, i.e. based on the build
configuration of the current Python interpreter. Pants builds single
platform wheels, so the wheels need to be tagged with the right CPU
architecture.

In #21655, we changed from tagging correctly to tagging incorrectly:

- Before that change, our self-hosted runners had 'simple' Python
interpreters, built for the current platform via Pyenv. `python -c
'import sysconfig; print(sysconfig.get_platform())' reports
`macosx-10.15-x86_64` and `macosx-11.6-arm64`, and indeed the wheels
were tagged like that.
- After that change, we started using Python interpreters provided by
GitHub-hosted runners. The interpreters report `macosx-10.9-universal2`
on both the ARM64 and x86-64 runners. That is, they're built as
universal binaries that can run on either architecture. This lead to the
wheels being tagged as `universal2` as well.

The `_PYTHON_HOST_PLATFORM` environment variable overrides the default
`sysconfig.get_platform()` value, and appears to be designed for this
sort of purpose (and is used by `cibuildwheel` for such):

-
https://github.com/python/cpython/blob/5505b91a684b0fc7ffcb3a5b325302671d74fb15/Lib/sysconfig.py#L652-L654
-
https://github.com/pypa/cibuildwheel/blob/3805787fe7a0476391541d834fa548a721f0ab2e/cibuildwheel/macos.py#L318-L331

Fixes #21938
@WorkerPants WorkerPants added this to the 2.25.x milestone Feb 11, 2025
@WorkerPants WorkerPants added the release-notes:not-required PR doesn't require mention in release notes label Feb 11, 2025
@huonw huonw enabled auto-merge (squash) February 11, 2025 05:43
@huonw huonw merged commit c142a3f into 2.25.x Feb 11, 2025
24 checks passed
@huonw huonw deleted the cherry-pick-21942-to-2.25.x branch February 11, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes:not-required PR doesn't require mention in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants