Skip to content

Commit ccf8989

Browse files
committed
TST: adjust for changes in pyproject-metadata 0.9.0
1 parent d638bc8 commit ccf8989

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dynamic = [
4747
[project.optional-dependencies]
4848
test = [
4949
'build',
50+
'packaging >= 23.1',
5051
'pytest >= 6.0',
5152
'pytest-cov[toml]',
5253
'pytest-mock',

tests/conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from venv import EnvBuilder
1818

19+
import packaging.metadata
1920
import packaging.version
2021
import pytest
2122

@@ -24,6 +25,12 @@
2425
from mesonpy._util import chdir
2526

2627

28+
def metadata(data):
29+
meta, other = packaging.metadata.parse_email(data)
30+
assert not other
31+
return meta
32+
33+
2734
def adjust_packaging_platform_tag(platform: str) -> str:
2835
if platform.startswith(('manylinux', 'musllinux')):
2936
# The packaging module generates overly specific platforms tags on

tests/test_metadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44

55
import pathlib
6+
import re
67

78
import packaging.version
89
import pyproject_metadata
@@ -48,5 +49,11 @@ def test_missing_version(package_missing_version):
4849
pyproject = {'project': {
4950
'name': 'missing-version',
5051
}}
51-
with pytest.raises(pyproject_metadata.ConfigurationError, match='Field "project.version" missing'):
52+
match = '|'.join((
53+
# pyproject-metatadata 0.8.0 and later
54+
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
55+
# pyproject-metatadata 0.9.0 and later
56+
re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'),
57+
))
58+
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
5259
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,50 @@
1414

1515
import mesonpy
1616

17-
from .conftest import in_git_repo_context
17+
from .conftest import in_git_repo_context, metadata
1818

1919

2020
def test_no_pep621(sdist_library):
2121
with tarfile.open(sdist_library, 'r:gz') as sdist:
22-
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()
22+
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read()
2323

24-
assert sdist_pkg_info == textwrap.dedent('''\
24+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
2525
Metadata-Version: 2.1
2626
Name: library
2727
Version: 1.0.0
28-
''')
28+
'''))
2929

3030

3131
def test_pep621(sdist_full_metadata):
3232
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
33-
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
33+
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read()
3434

35-
metadata = textwrap.dedent('''\
35+
meta = metadata(sdist_pkg_info)
36+
37+
# pyproject-metadata prior to 0.9.0 strips trailing newlines
38+
meta['license'] = meta['license'].rstrip()
39+
40+
# pyproject-metadata 0.9.0 and later does not emit Home-Page
41+
meta.pop('home_page', None)
42+
# nor normalizes Project-URL keys
43+
meta['project_urls'] = {k.lower(): v for k, v in meta['project_urls'].items()}
44+
45+
assert meta == metadata(textwrap.dedent('''\
3646
Metadata-Version: 2.1
3747
Name: full-metadata
3848
Version: 1.2.3
3949
Summary: Some package with all of the PEP 621 metadata
4050
Keywords: full,metadata,keyword with spaces
41-
Home-page: https://example.com
4251
Author: Jane Doe
4352
Author-Email: Unknown <[email protected]>
4453
Maintainer-Email: Jane Doe <[email protected]>
4554
License: some license
4655
Classifier: Development Status :: 4 - Beta
4756
Classifier: Programming Language :: Python
48-
Project-URL: Homepage, https://example.com
49-
Project-URL: Documentation, https://readthedocs.org
50-
Project-URL: Repository, https://github.com/mesonbuild/meson-python
51-
Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
57+
Project-URL: homepage, https://example.com
58+
Project-URL: documentation, https://readthedocs.org
59+
Project-URL: repository, https://github.com/mesonbuild/meson-python
60+
Project-URL: changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
5261
Requires-Python: >=3.7
5362
Requires-Dist: a
5463
Requires-Dist: b>1
@@ -67,20 +76,18 @@ def test_pep621(sdist_full_metadata):
6776
# full-metadata
6877
6978
An example package with all of the PEP 621 metadata!
70-
''')
71-
72-
assert sdist_pkg_info == metadata
79+
'''))
7380

7481

7582
def test_dynamic_version(sdist_dynamic_version):
7683
with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
77-
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode()
84+
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read()
7885

79-
assert sdist_pkg_info == textwrap.dedent('''\
86+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
8087
Metadata-Version: 2.1
8188
Name: dynamic-version
8289
Version: 1.0.0
83-
''')
90+
'''))
8491

8592

8693
def test_contents(sdist_library):

0 commit comments

Comments
 (0)