From e452159c2ac533441693e802c4d687f33f1608f8 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Thu, 10 Oct 2024 21:15:12 +0200 Subject: [PATCH 1/7] TST: adjust for changes in pyproject-metadata 0.9.0 --- pyproject.toml | 1 + tests/conftest.py | 7 ++++++ tests/test_metadata.py | 2 ++ tests/test_sdist.py | 49 +++++++++++++++++++++++++----------------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index af6814a6b..2c2e13237 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 088e82f7e..684c4c8d7 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -53,6 +53,8 @@ def test_missing_version(package_missing_version): re.escape('Required "project.version" field is missing'), # 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 e4dddb8c7..4a1444acb 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -4,52 +4,65 @@ import os import pathlib -import re import stat import sys import tarfile import textwrap import time +from itertools import chain + import pytest 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() + + meta = metadata(sdist_pkg_info) + + # pyproject-metadata prior to 0.8.0 uses spaces to join keywords + meta['keywords'] = list(chain(*(v.split(' ') for v in meta['keywords']))) - metadata = re.escape(textwrap.dedent('''\ + # 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 - Home-page: https://example.com + Keywords: full,metadata 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 @@ -70,20 +83,16 @@ def test_pep621(sdist_full_metadata): An example package with all of the PEP 621 metadata! ''')) - # pyproject-metadata 0.8.0 and later uses a comma to separate keywords - expr = metadata.replace(r'Keywords:\ full\ metadata', r'Keywords:\ full[ ,]metadata') - assert re.fullmatch(expr, sdist_pkg_info) - 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): From 01df256e4fbe0a75437e38000c37bb27ee1963a0 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 08:47:23 +0200 Subject: [PATCH 2/7] MAINT: fixes to comply with pyproject-metadata 0.9.0 type annotations --- mesonpy/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 0b968a62e..e858367d0 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -246,7 +246,7 @@ def _validate_name(name: str) -> str: return name @classmethod - def from_pyproject( + def from_pyproject( # type: ignore[override] cls, data: Mapping[str, Any], project_dir: Path = os.path.curdir, @@ -367,7 +367,7 @@ def _libs_dir(self) -> str: @property def _license_file(self) -> Optional[pathlib.Path]: license_ = self._metadata.license - if license_: + if license_ and isinstance(license_, pyproject_metadata.License): return license_.file return None From 3257da4bfc310e336004e0cbd80216f05443a613 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 14:04:47 +0200 Subject: [PATCH 3/7] TST: fix test to work correctly outside git work directory Fixes #695. --- tests/test_sdist.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/test_sdist.py b/tests/test_sdist.py index 4a1444acb..94e55c70e 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -218,12 +218,13 @@ def test_long_path(sdist_long_path): def test_reproducible(package_pure, tmp_path): - t1 = time.time() - sdist_path_a = mesonpy.build_sdist(tmp_path / 'a') - t2 = time.time() - # Ensure that the two sdists are build at least one second apart. - time.sleep(max(t1 + 1.0 - t2, 0.0)) - sdist_path_b = mesonpy.build_sdist(tmp_path / 'b') + with in_git_repo_context(): + t1 = time.time() + sdist_path_a = mesonpy.build_sdist(tmp_path / 'a') + t2 = time.time() + # Ensure that the two sdists are build at least one second apart. + time.sleep(max(t1 + 1.0 - t2, 0.0)) + sdist_path_b = mesonpy.build_sdist(tmp_path / 'b') assert sdist_path_a == sdist_path_b assert tmp_path.joinpath('a', sdist_path_a).read_bytes() == tmp_path.joinpath('b', sdist_path_b).read_bytes() From 82f27e82bf7912f99ab8998d84e563c898270acd Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 14:05:54 +0200 Subject: [PATCH 4/7] TST: drop superfluous call to os.fspath() --- tests/test_sdist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_sdist.py b/tests/test_sdist.py index 94e55c70e..7d3245e7f 100644 --- a/tests/test_sdist.py +++ b/tests/test_sdist.py @@ -2,7 +2,6 @@ # # SPDX-License-Identifier: MIT -import os import pathlib import stat import sys @@ -144,7 +143,7 @@ def bar(): try: pathlib.Path('pure.py').write_text(new) pathlib.Path('other.py').touch() - sdist_path = mesonpy.build_sdist(os.fspath(tmp_path)) + sdist_path = mesonpy.build_sdist(tmp_path) finally: pathlib.Path('pure.py').write_text(old) pathlib.Path('other.py').unlink() From 679e0e4f7b13911444f2e61eeec627502096605c Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 21:31:36 +0200 Subject: [PATCH 5/7] CI: test also with pyproject-metadata 0.8.0 --- .github/workflows/tests.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index bf8394976..5ac6f2af2 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -95,10 +95,13 @@ jobs: - os: windows-latest python: '3.12' meson: '@git+https://github.com/mesonbuild/meson.git' - # Test with oldest supported pyproject-metadata + # Test with older supported pyproject-metadata - os: ubuntu-latest python: '3.12' pyproject_metadata: '==0.7.1' + - os: ubuntu-latest + python: '3.12' + pyproject_metadata: '==0.8.0' steps: - name: Checkout From a2063744a24dacc10db83583f9f3c33ef79ff4ca Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 21:30:02 +0200 Subject: [PATCH 6/7] DOC: update changelog for 0.17.1 --- CHANGELOG.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f767c9ad3..386b5752d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,6 +11,14 @@ Changelog +++++++++ +0.17.1 +====== + +- Update tests to work with newly released ``pyproject-metadata`` 0.9.0. +- Fix tests to work when not executed in a git work tree. + +Daniele Nicolodi --- 23-10-2024. + 0.17.0 ====== From a2d5c87e3fe8cd0f9811be874c058bc827cafcc5 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Wed, 23 Oct 2024 21:27:31 +0200 Subject: [PATCH 7/7] REL: set version to 0.17.1 --- meson.build | 2 +- mesonpy/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 5b5098055..4f1b24222 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: MIT -project('meson-python', version: '0.17.0') +project('meson-python', version: '0.17.1') py = import('python').find_installation() diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index e858367d0..4d785a386 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -65,7 +65,7 @@ MesonArgs = Mapping[MesonArgsKeys, List[str]] -__version__ = '0.17.0.dev0' +__version__ = '0.17.1' _NINJA_REQUIRED_VERSION = '1.8.2'