Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be reading the packaging documentation wrong, but the default is prereleases=None and this is treated the same as prereleases=True (if this is not the case the documentation may require some clarification). Thus this change does not seem to be needed, namely setting prereleases = True can be simply dropped?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but this behavior was changed (by me) in packaging 26.0 to correctly match the spec.

So you would need to set packaging >= 26.0 in your pyproject.toml, and then yes, you can remove the line self._metadata.requires_python.prereleases = True.

I can update this PR to do that if you prefer.

raise MesonBuilderError(
f'The package requires Python version {self._metadata.requires_python}, '
f'running on {platform.python_version()}')
Expand Down
14 changes: 14 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Loading