Skip to content

Commit

Permalink
mesonpy: error out if we are running on an unsupported interpreter
Browse files Browse the repository at this point in the history
Fixes #69

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Jun 10, 2022
1 parent c01645a commit a394f9c
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
33 changes: 24 additions & 9 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,16 +384,8 @@ def __init__(
)
self._metadata = None

# check for unsupported dynamic fields
if self._metadata:
unsupported_dynamic = {
key for key in self._metadata.dynamic
if key not in self._ALLOWED_DYNAMIC_FIELDS
}
if unsupported_dynamic:
raise MesonBuilderError('Unsupported dynamic fields: {}'.format(
', '.join(unsupported_dynamic)),
)
self._validate_metadata()

# make sure the build dir exists
self._build_dir.mkdir(exist_ok=True)
Expand Down Expand Up @@ -458,6 +450,29 @@ def _configure(self, reconfigure: bool = False) -> None:
else:
raise

def _validate_metadata(self) -> None:
assert self._metadata

# check for unsupported dynamic fields
unsupported_dynamic = {
key for key in self._metadata.dynamic
if key not in self._ALLOWED_DYNAMIC_FIELDS
}
if unsupported_dynamic:
raise MesonBuilderError('Unsupported dynamic fields: {}'.format(
', '.join(unsupported_dynamic)),
)

# check if we are running on an unsupported interpreter
if (
self._metadata.requires_python
and platform.python_version() not in self._metadata.requires_python
):
raise MesonBuilderError(
f'Unsupported Python version `{platform.python_version()}`, '
f'expected `{self._metadata.requires_python}`'
)

@functools.lru_cache(maxsize=None)
def build(self) -> None:
self._meson('compile')
Expand Down
2 changes: 1 addition & 1 deletion tests/packages/full-metadata/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = 'full-metadata'
version = '1.2.3'
description = 'Some package with all of the PEP 621 metadata'
readme = 'README.md'
requires-python = '>=3.10'
requires-python = '>=3.7'
license = {file = 'LICENSE'}
keywords = ['full', 'metadata']
authors = [
Expand Down
4 changes: 4 additions & 0 deletions tests/packages/unsupported-python-version/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
project(
'unsupported-python-version',
version: '1.0.0',
)
8 changes: 8 additions & 0 deletions tests/packages/unsupported-python-version/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[build-system]
build-backend = 'mesonpy'
requires = ['meson-python']

[project]
name = 'unsupported-python-version'
version = '1.2.3'
requires-python = '==1.0.0'
2 changes: 1 addition & 1 deletion tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_pep621(sdist_full_metadata):
Project-URL: Documentation, https://readthedocs.org
Project-URL: Repository, https://github.com/FFY00/mesonpy
Project-URL: Changelog, https://github.com/FFY00/mesonpy/blob/master/CHANGELOG.md
Requires-Python: >=3.10
Requires-Python: >=3.7
Requires-Dist: a
Requires-Dist: b>1
Requires-Dist: c>2; os_name != "nt"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: EUPL-1.2

import platform

import pytest

import mesonpy
Expand Down Expand Up @@ -35,3 +37,12 @@ def test_unsupported_dynamic(package_unsupported_dynamic):
with pytest.raises(mesonpy.MesonBuilderError, match='Unsupported dynamic fields: dependencies'):
with mesonpy.Project.with_temp_working_dir():
pass


def test_unsupported_python_version(package_unsupported_python_version):
with pytest.raises(mesonpy.MesonBuilderError, match=(
f'Unsupported Python version `{platform.python_version()}`, '
'expected `==1.0.0`'
)):
with mesonpy.Project.with_temp_working_dir():
pass

0 comments on commit a394f9c

Please sign in to comment.