From bc25261e974aaf992cc15c497f66ef02945da6e5 Mon Sep 17 00:00:00 2001 From: Daniele Nicolodi Date: Sat, 12 Oct 2024 21:48:16 +0200 Subject: [PATCH] BUG: adjust to older pyproject-metadata releases --- mesonpy/__init__.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 75487c111..02a7a2ed8 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -78,6 +78,7 @@ def canonicalize_license_expression(s: str) -> str: __version__ = '0.17.0.dev0' +_PYPROJECT_METADATA_VERSION = tuple(map(int, pyproject_metadata.__version__.split('.')[:2])) _NINJA_REQUIRED_VERSION = '1.8.2' _MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml @@ -244,6 +245,9 @@ class MesonBuilderError(Error): class Metadata(pyproject_metadata.StandardMetadata): def __init__(self, name: str, *args: Any, **kwargs: Any): + if _PYPROJECT_METADATA_VERSION < (0, 9): + kwargs.pop('license', None) + kwargs.pop('license_files', None) super().__init__(name, *args, **kwargs) # Local fix for https://github.com/FFY00/python-pyproject-metadata/issues/60 self.name = self._validate_name(name) @@ -758,7 +762,12 @@ def __init__( if license is None: raise pyproject_metadata.ConfigurationError( 'Field "license" declared as dynamic but license is not specified in meson.build') - self._metadata.license = license + # mypy is not happy when analyzing typing based on + # pyproject-metadata < 0.9 where license needs to be of + # License type. However, this code is not executed if + # pyproject-metadata is older than 0.9 because then dynamic + # license is not allowed. + self._metadata.license = license # type: ignore[assignment] if 'license-files' in self._metadata.dynamic: self._metadata.license_files = self._meson_license_files else: @@ -908,7 +917,7 @@ def _meson_license(self) -> Optional[str]: assert isinstance(value, str) if value == 'unknown': return None - return canonicalize_license_expression(value) + return str(canonicalize_license_expression(value)) # str() is to make mypy happy @property def _meson_license_files(self) -> List[pathlib.Path]: