1414else :
1515 import tomllib
1616
17- import pyproject_metadata
1817import pytest
1918
2019import mesonpy
2120
22- from .conftest import in_git_repo_context , package_dir
21+ from .conftest import in_git_repo_context , package_dir , metadata , MESON_VERSION , PYPROJECT_METADATA_VERSION
2322
2423
2524def test_unsupported_python_version (package_unsupported_python_version ):
@@ -40,6 +39,94 @@ def test_missing_dynamic_version(package_missing_dynamic_version):
4039 pass
4140
4241
42+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
43+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
44+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
45+ def test_meson_build_metadata (tmp_path ):
46+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
47+ [build-system]
48+ build-backend = 'mesonpy'
49+ requires = ['meson-python']
50+ ''' ), encoding = 'utf8' )
51+
52+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
53+ project('test', version: '1.2.3', license: 'MIT', license_files: 'LICENSE')
54+ ''' ), encoding = 'utf8' )
55+
56+ tmp_path .joinpath ('LICENSE' ).write_text ('' )
57+
58+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
59+
60+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
61+ Metadata-Version: 2.4
62+ Name: test
63+ Version: 1.2.3
64+ License-Expression: MIT
65+ License-File: LICENSE
66+ ''' ))
67+
68+
69+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
70+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
71+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
72+ def test_dynamic_license (tmp_path ):
73+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
74+ [build-system]
75+ build-backend = 'mesonpy'
76+ requires = ['meson-python']
77+
78+ [project]
79+ name = 'test'
80+ version = '1.0.0'
81+ dynamic = ['license']
82+ ''' ), encoding = 'utf8' )
83+
84+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
85+ project('test', license: 'MIT')
86+ ''' ), encoding = 'utf8' )
87+
88+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
89+
90+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
91+ Metadata-Version: 2.4
92+ Name: test
93+ Version: 1.0.0
94+ License-Expression: MIT
95+ ''' ))
96+
97+
98+ @pytest .mark .skipif (PYPROJECT_METADATA_VERSION < (0 , 9 ), reason = 'pyproject-metadata too old' )
99+ @pytest .mark .skipif (MESON_VERSION < (1 , 6 , 0 ), reason = 'meson too old' )
100+ @pytest .mark .filterwarnings ('ignore:canonicalization and validation of license expression' )
101+ def test_dynamic_license_files (tmp_path ):
102+ tmp_path .joinpath ('pyproject.toml' ).write_text (textwrap .dedent ('''
103+ [build-system]
104+ build-backend = 'mesonpy'
105+ requires = ['meson-python']
106+
107+ [project]
108+ name = 'test'
109+ version = '1.0.0'
110+ dynamic = ['license', 'license-files']
111+ ''' ), encoding = 'utf8' )
112+
113+ tmp_path .joinpath ('meson.build' ).write_text (textwrap .dedent ('''
114+ project('test', license: 'MIT', license_files: ['LICENSE'])
115+ ''' ), encoding = 'utf8' )
116+
117+ tmp_path .joinpath ('LICENSE' ).write_text ('' )
118+
119+ p = mesonpy .Project (tmp_path , tmp_path / 'build' )
120+
121+ assert metadata (bytes (p ._metadata .as_rfc822 ())) == metadata (textwrap .dedent ('''\
122+ Metadata-Version: 2.4
123+ Name: test
124+ Version: 1.0.0
125+ License-Expression: MIT
126+ License-File: LICENSE
127+ ''' ))
128+
129+
43130def test_user_args (package_user_args , tmp_path , monkeypatch ):
44131 project_run = mesonpy .Project ._run
45132 cmds = []
0 commit comments