From 9ffff411b5733068b911ff283dd741d75921eb5e Mon Sep 17 00:00:00 2001 From: Damian Shaw Date: Mon, 19 Oct 2026 13:11:52 -0400 Subject: [PATCH] BUG: avoid mutating interpreter prerelease policy --- mesonpy/__init__.py | 5 +++-- tests/test_project.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 57d218c82..3ff6618de 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -925,8 +925,9 @@ def __init__(self, # verify that we are running on a supported interpreter if self._metadata.requires_python: - self._metadata.requires_python.prereleases = True - if platform.python_version().rstrip('+') not in self._metadata.requires_python: + if not self._metadata.requires_python.contains( + platform.python_version().rstrip('+'), prereleases=True + ): raise MesonBuilderError( f'The package requires Python version {self._metadata.requires_python}, ' f'running on {platform.python_version()}') diff --git a/tests/test_project.py b/tests/test_project.py index a6f711ccf..53b4a8a6c 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -34,6 +34,20 @@ def test_unsupported_python_version(package_unsupported_python_version): pass +def test_prerelease_python_version(tmp_path, monkeypatch): + tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent('''\ + [project] + name = 'prerelease-python-version' + version = '1.0.0' + requires-python = '>=3.9' + '''), encoding='utf8') + tmp_path.joinpath('meson.build').write_text("project('prerelease-python-version', version: '1.0.0')", encoding='utf8') + monkeypatch.setattr(platform, 'python_version', lambda: '3.12.0rc1') + + project = mesonpy.Project(tmp_path, tmp_path / 'build') + assert project._metadata.requires_python.prereleases is None + + def test_missing_meson_version(package_missing_meson_version): with pytest.raises(pyproject_metadata.ConfigurationError, match='Section "project" missing in pyproject.toml'): with mesonpy._project():