Skip to content

MAINT: require pyproject-metadata 0.10.0 - #939

Open
CAOShurong wants to merge 5 commits into
mesonbuild:mainfrom
CAOShurong:fix/pep794-metadata-parser
Open

CAOShurong wants to merge 5 commits into
mesonbuild:mainfrom
CAOShurong:fix/pep794-metadata-parser

Conversation

@CAOShurong

@CAOShurong CAOShurong commented Nov 29, 2026 •

Copy link
Copy Markdown

Fixes #809.

Raise the build and runtime minimum to pyproject-metadata 0.10.0, the first release that reads import-names and import-namespaces. Align the CI and Pixi constraints and keep the regression test for the Core Metadata 2.5 headers.

Verified five wheel builds on Windows with pyproject-metadata 0.10.0 and packaging 23.2, covering explicit import names and namespaces, an empty import-name list, and license metadata. The built backend installs with 0.10.0 and 0.12.1. The dependency resolver rejects 0.9.0.

@dnicolodi

dnicolodi commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

We don't do similar checks for other metadata fields (PEP 639 license-files for example). Introducing this check for PEP 794 fields requires some discussion.

@rgommers

rgommers commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@dnicolodi what do you think about just dropping 0.9.0? 0.10.0 is over a year old by now, and there's no reason (unlike for our meson dependency) to be overly conservative here.

@dnicolodi

Copy link
Copy Markdown
Member

I do not see any reason to do not bump the required pyproject-metadata version. A separate question is whether we should error on extra keys fond in the project table in pyproject.toml.

Raise the build and runtime minimum to the first release that supports
PEP 794. Align the CI minimums and keep the metadata 2.5 regression.
@CAOShurong CAOShurong changed the title BUG: reject import metadata with an older parser MAINT: require pyproject-metadata 0.10.0 Dec 2, 2026
@rgommers

rgommers commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

A separate question is whether we should error on extra keys fond in the project table in pyproject.toml.

I would say yes, that needs an exception with a clear message. Either an unclear exception or metadata silently going missing seems like a usability issue to me.

@rgommers rgommers added the maintenance Regular code improvements that are not new features nor end-user-visible bugs label Dec 2, 2026

@rgommers rgommers left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice, this LGTM now.

@rgommers

rgommers commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Modulo commit history that is, since we normally rebase-merge and require a clean commit history. We can squash-merge though I think.

Keyword validation is no longer relevant for this PR given the >=1.10.0 bump, but it may be a separate thing to follow up on (I didn't check).

Comment thread tests/test_metadata.py Outdated
Comment on lines +88 to +100


def test_import_metadata_rfc822():
data = {'project': {
'name': 'test',
'version': '1.0.0',
'import-names': ['shared.example'],
'import-namespaces': ['shared'],
}}
metadata = Metadata.from_pyproject(data).as_rfc822()
assert metadata['Metadata-Version'] == '2.5'
assert metadata.get_all('Import-Name') == ['shared.example']
assert metadata.get_all('Import-Namespace') == ['shared']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be dropped: we have no interest in validating pyproject-metadata correctness.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggested that at #809 (comment). And we're doing this kind of test in multiple places already (just search for Metadata-Version), so I don't think this comment is right. It's in the end the artifact we produce, and it's useful to have one test per feature. It should work regardless of whether we call pyproject-metadata, packaging in the future (if the functionality gets upstreamed), or rework it in some other way.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the direct parser test in 06bf3fd. The replacement builds a wheel and checks Import-Name and Import-Namespace in its .dist-info/METADATA.

@dnicolodi dnicolodi Dec 2, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And we're doing this kind of test in multiple places already (just search for Metadata-Version), so I don't think this comment is right.

The tests I could find verify metadata compilation by meson-python (handling of dynamic metadata, presence of license files, etc..). The test added here does not test anything implemented by meson-python. However, we can keep it, if you think it is useful.

My general policy for tests is that at least one of tho things need to be true for making a test worth having:

  • can the project carrying the test fix something if the test starts failing?
  • can the project carrying the test do introduce a change that can make the test fail?

In the case at hand, I think the answer is no to both questions. Thus I think the test is redundant.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The test got already adapted in the meantime; I think we can figure out the optimal form here (I don't think a whole new test package is it), but I do think we need one test for import-names and import-namespaces. It's a feature build backend support, and we want to get signal if it'd stop working.

I think adding these keys to an existing test package (TBD which one) and updating the expected Core Metadata version and content would be reasonable?

I'd also write it in a single assert rather than three separate ones, a la:

assert metadata(artifact.read('license_pep639-1.0.0.dist-info/METADATA')) == metadata(textwrap.dedent('''\
Metadata-Version: 2.4
Name: license-pep639
Version: 1.0.0
License-Expression: MIT OR BSD-3-Clause
License-File: LICENSES/BSD-3-Clause.txt
License-File: LICENSES/MIT.txt

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Switched the test to the existing module-types package in 8aeb43d. It now checks the complete wheel metadata in one assertion, including the native module and the namespace package. The separate fixture is gone.

Comment thread tests/conftest.py Outdated
Comment on lines +50 to +53
# Older packaging releases return PEP 794 headers as unparsed fields.
for header, field in (('import-name', 'import_names'), ('import-namespace', 'import_namespaces')):
if header in other:
meta[field] = other.pop(header)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This handles older versions of packaging in the wheel test. On the same wheel, parse_email() in 23.2, 24.2 and 25.0 returns Import-Name and Import-Namespace in the unparsed mapping, so the helper would fail at assert not other. In 26.0 it recognizes both. The loop keeps all four import names and the namespace for the metadata assertion, like the PEP 639 handling above it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's not the way to handle this - just skip the test instead if the packaging version is too old, same as for a meson version that's too old:

@pytest.mark.skipif(MESON_VERSION < (1, 6, 0), reason='meson too old')

@dnicolodi dnicolodi Dec 3, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think that having to add the handling of these fields here may be due to having added the test for PEP 794 to an existing test package. Otherwise, it is not needed at all, because the added test checks for the METADATA file to have some specific content, without parsing it.

The best way to do add the test is IMO to use a synthetic test package, like done in #923.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That sounds good to me.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry, I misread the test code. The test code parses the METADATA file. Therefore the parsing would need to be updated. However, skipping the test on too old packaging as @rgommers suggested is a better solution.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Removed the compatibility loop in dff3fbd. The import-name test now skips with packaging older than 26.0. With 26.0, the real module-types wheel still passes the full METADATA assertion. The Windows wheel suite passed with both 23.2 and 26.0.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Regular code improvements that are not new features nor end-user-visible bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for PEP 794 (import name metadata)

3 participants