diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bf8394976..62b63efd3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -99,6 +99,10 @@ jobs: - os: ubuntu-latest python: '3.12' pyproject_metadata: '==0.7.1' + # Tets with pyproject-metadata release candidate + - os: ubuntu-latest + python: '3.12' + pyproject_metadata: '==0.9.0rc1' steps: - name: Checkout diff --git a/pyproject.toml b/pyproject.toml index 661ac17e2..eaa4380e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,7 @@ dynamic = [ [project.optional-dependencies] test = [ 'build', + 'packaging >= 23.1', 'pytest >= 6.0', 'pytest-cov[toml]', 'pytest-mock', diff --git a/tests/conftest.py b/tests/conftest.py index 48ae12c3d..54964be9d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,7 @@ from venv import EnvBuilder +import packaging.metadata import packaging.version import pytest @@ -24,6 +25,12 @@ from mesonpy._util import chdir +def metadata(data): + meta, other = packaging.metadata.parse_email(data) + assert not other + return meta + + def adjust_packaging_platform_tag(platform: str) -> str: if platform.startswith(('manylinux', 'musllinux')): # The packaging module generates overly specific platforms tags on diff --git a/tests/test_metadata.py b/tests/test_metadata.py index 6906a3972..d219b90ce 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -3,6 +3,7 @@ # SPDX-License-Identifier: MIT import pathlib +import re import packaging.version import pyproject_metadata @@ -48,5 +49,11 @@ def test_missing_version(package_missing_version): pyproject = {'project': { 'name': 'missing-version', }} - with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'): + match = '|'.join(( + # pyproject-metatadata 0.8.0 and later + re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'), + # pyproject-metatadata 0.9.0 and later + re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'), + )) + with pytest.raises(pyproject_metadata.ConfigurationError, match=match): Metadata.from_pyproject(pyproject, pathlib.Path()) diff --git a/tests/test_sdist.py b/tests/test_sdist.py index bb9643628..83739d4d0 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -14,41 +14,50 @@ import mesonpy -from .conftest import in_git_repo_context +from .conftest import in_git_repo_context, metadata def test_no_pep621(sdist_library): with tarfile.open(sdist_library, 'r:gz') as sdist: - sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode() + sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read() - assert sdist_pkg_info == textwrap.dedent('''\ + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ Metadata-Version: 2.1 Name: library Version: 1.0.0 - ''') + ''')) def test_pep621(sdist_full_metadata): with tarfile.open(sdist_full_metadata, 'r:gz') as sdist: - sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode() + sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read() - metadata = textwrap.dedent('''\ + meta = metadata(sdist_pkg_info) + + # pyproject-metadata prior to 0.9.0 strips trailing newlines + meta['license'] = meta['license'].rstrip() + + # pyproject-metadata 0.9.0 and later does not emit Home-Page + meta.pop('home_page', None) + # nor normalizes Project-URL keys + meta['project_urls'] = {k.lower(): v for k, v in meta['project_urls'].items()} + + assert meta == metadata(textwrap.dedent('''\ Metadata-Version: 2.1 Name: full-metadata Version: 1.2.3 Summary: Some package with all of the PEP 621 metadata Keywords: full,metadata,keyword with spaces - Home-page: https://example.com Author: Jane Doe Author-Email: Unknown Maintainer-Email: Jane Doe License: some license Classifier: Development Status :: 4 - Beta Classifier: Programming Language :: Python - Project-URL: Homepage, https://example.com - Project-URL: Documentation, https://readthedocs.org - Project-URL: Repository, https://github.com/mesonbuild/meson-python - Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst + Project-URL: homepage, https://example.com + Project-URL: documentation, https://readthedocs.org + Project-URL: repository, https://github.com/mesonbuild/meson-python + Project-URL: changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst Requires-Python: >=3.7 Requires-Dist: a Requires-Dist: b>1 @@ -67,20 +76,18 @@ def test_pep621(sdist_full_metadata): # full-metadata An example package with all of the PEP 621 metadata! - ''') - - assert sdist_pkg_info == metadata + ''')) def test_dynamic_version(sdist_dynamic_version): with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist: - sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode() + sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read() - assert sdist_pkg_info == textwrap.dedent('''\ + assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\ Metadata-Version: 2.1 Name: dynamic-version Version: 1.0.0 - ''') + ''')) def test_contents(sdist_library):