Skip to content

Commit 296e713

Browse files
committed
TST: adjust for changes in pyproject-metadata 0.9.0
1 parent 2a30ac9 commit 296e713

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ def test_missing_version(package_missing_version):
5353
re.escape('Required "project.version" field is missing'),
5454
# pyproject-metatadata 0.8.0 and later
5555
re.escape('Field "project.version" missing and "version" not specified in "project.dynamic"'),
56+
# pyproject-metatadata 0.9.0 and later
57+
re.escape('Field "project.version" missing and \'version\' not specified in "project.dynamic"'),
5658
))
5759
with pytest.raises(pyproject_metadata.ConfigurationError, match=match):
5860
Metadata.from_pyproject(pyproject, pathlib.Path())

tests/test_sdist.py

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,52 +4,65 @@
44

55
import os
66
import pathlib
7-
import re
87
import stat
98
import sys
109
import tarfile
1110
import textwrap
1211
import time
1312

13+
from itertools import chain
14+
1415
import pytest
1516

1617
import mesonpy
1718

18-
from .conftest import in_git_repo_context
19+
from .conftest import in_git_repo_context, metadata
1920

2021

2122
def test_no_pep621(sdist_library):
2223
with tarfile.open(sdist_library, 'r:gz') as sdist:
23-
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read().decode()
24+
sdist_pkg_info = sdist.extractfile('library-1.0.0/PKG-INFO').read()
2425

25-
assert sdist_pkg_info == textwrap.dedent('''\
26+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
2627
Metadata-Version: 2.1
2728
Name: library
2829
Version: 1.0.0
29-
''')
30+
'''))
3031

3132

3233
def test_pep621(sdist_full_metadata):
3334
with tarfile.open(sdist_full_metadata, 'r:gz') as sdist:
34-
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read().decode()
35+
sdist_pkg_info = sdist.extractfile('full_metadata-1.2.3/PKG-INFO').read()
36+
37+
meta = metadata(sdist_pkg_info)
38+
39+
# pyproject-metadata prior to 0.8.0 uses spaces to join keywords
40+
meta['keywords'] = list(*chain(v.split(' ') for v in meta['keywords']))
3541

36-
metadata = re.escape(textwrap.dedent('''\
42+
# pyproject-metadata prior to 0.9.0 strips trailing newlines
43+
meta['license'] = meta['license'].rstrip()
44+
45+
# pyproject-metadata 0.9.0 and later does not emit Home-Page
46+
meta.pop('home_page', None)
47+
# nor normalizes Project-URL keys
48+
meta['project_urls'] = {k.lower(): v for k, v in meta['project_urls'].items()}
49+
50+
assert meta == metadata(textwrap.dedent('''\
3751
Metadata-Version: 2.1
3852
Name: full-metadata
3953
Version: 1.2.3
4054
Summary: Some package with all of the PEP 621 metadata
41-
Keywords: full metadata
42-
Home-page: https://example.com
55+
Keywords: full,metadata
4356
Author: Jane Doe
4457
Author-Email: Unknown <[email protected]>
4558
Maintainer-Email: Jane Doe <[email protected]>
4659
License: some license
4760
Classifier: Development Status :: 4 - Beta
4861
Classifier: Programming Language :: Python
49-
Project-URL: Homepage, https://example.com
50-
Project-URL: Documentation, https://readthedocs.org
51-
Project-URL: Repository, https://github.com/mesonbuild/meson-python
52-
Project-URL: Changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
62+
Project-URL: homepage, https://example.com
63+
Project-URL: documentation, https://readthedocs.org
64+
Project-URL: repository, https://github.com/mesonbuild/meson-python
65+
Project-URL: changelog, https://github.com/mesonbuild/meson-python/blob/master/CHANGELOG.rst
5366
Requires-Python: >=3.7
5467
Requires-Dist: a
5568
Requires-Dist: b>1
@@ -70,20 +83,16 @@ def test_pep621(sdist_full_metadata):
7083
An example package with all of the PEP 621 metadata!
7184
'''))
7285

73-
# pyproject-metadata 0.8.0 and later uses a comma to separate keywords
74-
expr = metadata.replace(r'Keywords:\ full\ metadata', r'Keywords:\ full[ ,]metadata')
75-
assert re.fullmatch(expr, sdist_pkg_info)
76-
7786

7887
def test_dynamic_version(sdist_dynamic_version):
7988
with tarfile.open(sdist_dynamic_version, 'r:gz') as sdist:
80-
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read().decode()
89+
sdist_pkg_info = sdist.extractfile('dynamic_version-1.0.0/PKG-INFO').read()
8190

82-
assert sdist_pkg_info == textwrap.dedent('''\
91+
assert metadata(sdist_pkg_info) == metadata(textwrap.dedent('''\
8392
Metadata-Version: 2.1
8493
Name: dynamic-version
8594
Version: 1.0.0
86-
''')
95+
'''))
8796

8897

8998
def test_contents(sdist_library):

0 commit comments

Comments
 (0)