Visitar URL original
MAINT: avoid mutating metadata.requires_python · mesonbuild/meson-python@dc84b4a · GitHub
Skip to content

Commit dc84b4a

Browse files
notatallshawdnicolodi
authored andcommitted
MAINT: avoid mutating metadata.requires_python
The packaging maintainers plan to deprecate mutability of packaging's core objects to improve performance and hashability. Avoid mutating the packaging.SpecifierSet object used to hold the requires-python specifier when matching against the current Python version.
1 parent 70d921d commit dc84b4a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎mesonpy/__init__.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,7 @@ def __init__(self,
925925

926926
# verify that we are running on a supported interpreter
927927
if self._metadata.requires_python:
928-
self._metadata.requires_python.prereleases = True
929-
if platform.python_version().rstrip('+') not in self._metadata.requires_python:
928+
if not self._metadata.requires_python.contains(platform.python_version().rstrip('+'), prereleases=True):
930929
raise MesonBuilderError(
931930
f'The package requires Python version {self._metadata.requires_python}, '
932931
f'running on {platform.python_version()}')

‎tests/test_project.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,23 @@ def test_unsupported_python_version(package_unsupported_python_version):
3434
pass
3535

3636

37+
def test_prerelease_python_version(tmp_path, monkeypatch):
38+
tmp_path.joinpath('pyproject.toml').write_text(textwrap.dedent('''
39+
[project]
40+
name = 'prerelease-python-version'
41+
version = '1.0.0'
42+
requires-python = '>=3.9'
43+
'''), encoding='utf8')
44+
45+
tmp_path.joinpath('meson.build').write_text(textwrap.dedent('''
46+
project('prerelease-python-version', version: '1.0.0')
47+
'''), encoding='utf8')
48+
49+
monkeypatch.setattr(platform, 'python_version', lambda: '3.12.0rc1')
50+
51+
p = mesonpy.Project(tmp_path, tmp_path / 'build')
52+
53+
3754
def test_missing_meson_version(package_missing_meson_version):
3855
with pytest.raises(pyproject_metadata.ConfigurationError, match='Section "project" missing in pyproject.toml'):
3956
with mesonpy._project():

0 commit comments

Comments
 (0)