diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 57d218c82..2f3cdfa14 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -925,8 +925,7 @@ 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..1438844f1 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -34,6 +34,27 @@ 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(''' + [build-system] + build-backend = 'mesonpy' + requires = ['meson-python'] + + [project] + name = 'test' + version = '1.0.0' + requires-python = '>=3.9' + '''), encoding='utf8') + + tmp_path.joinpath('meson.build').write_text(textwrap.dedent(''' + project('test', version: '1.0.0') + '''), encoding='utf8') + + monkeypatch.setattr(platform, 'python_version', lambda: '3.12.0rc1') + + mesonpy.Project(tmp_path, tmp_path / 'build') + + 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():