44
55import os
66import pathlib
7- import re
87import stat
98import sys
109import tarfile
1514
1615import mesonpy
1716
18- from .conftest import in_git_repo_context
17+ from .conftest import in_git_repo_context , metadata
1918
2019
2120def test_no_pep621 (sdist_library ):
2221 with tarfile .open (sdist_library , 'r:gz' ) as sdist :
23- 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 ()
2423
25- assert sdist_pkg_info == textwrap .dedent ('''\
24+ assert metadata ( sdist_pkg_info ) == metadata ( textwrap .dedent ('''\
2625 Metadata-Version: 2.1
2726 Name: library
2827 Version: 1.0.0
29- ''' )
28+ ''' ))
3029
3130
3231def test_pep621 (sdist_full_metadata ):
3332 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 ()
33+ sdist_pkg_info = sdist .extractfile ('full_metadata-1.2.3/PKG-INFO' ).read ()
34+
35+ meta = metadata (sdist_pkg_info )
36+
37+ # pyproject-metadata prior to 0.9.0 strips trailing newlines
38+ meta ['license' ] = meta ['license' ].rstrip ()
3539
36- metadata = re .escape (textwrap .dedent ('''\
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 ('''\
3746 Metadata-Version: 2.1
3847 Name: full-metadata
3948 Version: 1.2.3
4049 Summary: Some package with all of the PEP 621 metadata
41- Keywords: full metadata
42- Home-page: https://example.com
50+ Keywords: full,metadata
4351 Author: Jane Doe
4452 Author-Email: Unknown <[email protected] > 4553 Maintainer-Email: Jane Doe <[email protected] > 4654 License: some license
4755 Classifier: Development Status :: 4 - Beta
4856 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
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
5361 Requires-Python: >=3.7
5462 Requires-Dist: a
5563 Requires-Dist: b>1
@@ -70,20 +78,16 @@ def test_pep621(sdist_full_metadata):
7078 An example package with all of the PEP 621 metadata!
7179 ''' ))
7280
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-
7781
7882def test_dynamic_version (sdist_dynamic_version ):
7983 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 ()
84+ sdist_pkg_info = sdist .extractfile ('dynamic_version-1.0.0/PKG-INFO' ).read ()
8185
82- assert sdist_pkg_info == textwrap .dedent ('''\
86+ assert metadata ( sdist_pkg_info ) == metadata ( textwrap .dedent ('''\
8387 Metadata-Version: 2.1
8488 Name: dynamic-version
8589 Version: 1.0.0
86- ''' )
90+ ''' ))
8791
8892
8993def test_contents (sdist_library ):
0 commit comments