Repository navigation
Conversation
The core metadata of a wheel must start with Metadata-Version, and the METADATA that `python_wheel` writes had none. Strict validators reject such a wheel: `packaging.metadata.Metadata.from_email(validate=True)` fails with "None is not a valid metadata version". pip and uv install it anyway. Write `Metadata-Version: 2.1` first, the oldest version with every field the rule writes (`Description-Content-Type` is 2.1). A Metadata-Version passed through `extra_metadata` replaces it, for wheels that use later fields.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D134830465. (Because this pull request was imported automatically, there will not be any future comments.) |
Contributor
|
This pull request has been merged in 4268187. |
meta-codesync Bot
pushed a commit
to meta/buck2-prelude
that referenced
this pull request
Nov 28, 2026
Summary:
The `METADATA` file that `python_wheel` writes (`prelude/python/tools/wheel.py`) starts with `Name` and `Version` and has no `Metadata-Version`, which the core metadata specification requires. Strict validators reject such a wheel. pip and uv install it anyway, so the problem only shows once the wheel meets a strict check.
This PR writes `Metadata-Version: 2.1` as the first field. 2.1 is the oldest version that covers every field the rule writes: `Description-Content-Type` was added in 2.1, while `Requires-Dist` and `Requires-Python` date from 1.2. A `Metadata-Version` passed through `extra_metadata` takes its place, for wheels that use later fields, so the header never appears twice.
## Affected version
origin/main 00c2ee4f74. Neither `wheel.py` nor `python_wheel.bzl` has ever written the field.
## Reproduction
```
python3 prelude/python/tools/wheel.py --output my_pkg-1.0.0-py3-none-any.whl --name my-pkg --version 1.0.0 \
--metadata Requires-Python '==3.14.*' --src-path mypkg/core.py src/mypkg/core.py
unzip -p my_pkg-1.0.0-py3-none-any.whl my_pkg-1.0.0.dist-info/METADATA > METADATA
python3 -c 'import packaging.metadata as pm; pm.Metadata.from_email(open("METADATA").read(), validate=True)'
```
## Expected
The metadata validates.
## Actual
```
Name: my-pkg
Version: 1.0.0
Requires-Python: ==3.14.*
```
`packaging` 26.4 raises `ExceptionGroup: ['None is not a valid metadata version']`. The same file with `Metadata-Version: 2.1` prepended validates.
X-link: meta/buck2#1668
Reviewed By: dtolnay
Differential Revision: D134830465
fbshipit-source-id: 6c638c459b4bfb082942c0a6bde01916f03038c9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
METADATAfile thatpython_wheelwrites (prelude/python/tools/wheel.py) starts withNameandVersionand has noMetadata-Version, which the core metadata specification requires. Strict validators reject such a wheel. pip and uv install it anyway, so the problem only shows once the wheel meets a strict check.This PR writes
Metadata-Version: 2.1as the first field. 2.1 is the oldest version that covers every field the rule writes:Description-Content-Typewas added in 2.1, whileRequires-DistandRequires-Pythondate from 1.2. AMetadata-Versionpassed throughextra_metadatatakes its place, for wheels that use later fields, so the header never appears twice.Affected version
origin/main 00c2ee4. Neither
wheel.pynorpython_wheel.bzlhas ever written the field.Reproduction
Expected
The metadata validates.
Actual
packaging26.4 raisesExceptionGroup: ['None is not a valid metadata version']. The same file withMetadata-Version: 2.1prepended validates.Test plan
prelude/python/tools/tests/wheel_test.py:test_metadata_starts_with_metadata_versionfails without the change and passes with it.test_metadata_version_given_by_the_caller_is_keptchecks that a caller'sMetadata-Versionis the only one in the file.METADATAof the wheel above validates withpackaging26.4, and pip still installs the wheel and imports its module.