Skip to content

Commit 79339f3

Browse files
committed
BUG: adjust to older pyproject-metadata releases
1 parent 902e04d commit 79339f3

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

mesonpy/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def canonicalize_license_expression(s: str) -> str:
7878

7979
__version__ = '0.17.0.dev0'
8080

81+
_PYPROJECT_METADATA_VERSION = tuple(map(int, pyproject_metadata.__version__.split('.')[:2]))
8182

8283
_NINJA_REQUIRED_VERSION = '1.8.2'
8384
_MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml
@@ -244,6 +245,9 @@ class MesonBuilderError(Error):
244245

245246
class Metadata(pyproject_metadata.StandardMetadata):
246247
def __init__(self, name: str, *args: Any, **kwargs: Any):
248+
if _PYPROJECT_METADATA_VERSION < (0, 9):
249+
kwargs.pop('license', None)
250+
kwargs.pop('license_files', None)
247251
super().__init__(name, *args, **kwargs)
248252
# Local fix for https://github.com/FFY00/python-pyproject-metadata/issues/60
249253
self.name = self._validate_name(name)
@@ -759,7 +763,12 @@ def __init__(
759763
if license is None:
760764
raise pyproject_metadata.ConfigurationError(
761765
'Field "license" declared as dynamic but license is not specified in meson.build')
762-
self._metadata.license = license
766+
# mypy is not happy when analyzing typing based on
767+
# pyproject-metadata < 0.9 where license needs to be of
768+
# License type. However, this code is not executed if
769+
# pyproject-metadata is older than 0.9 because then dynamic
770+
# license is not allowed.
771+
self._metadata.license = license # type: ignore[assignment]
763772
if 'license-files' in self._metadata.dynamic:
764773
self._metadata.license_files = self._meson_license_files
765774
else:
@@ -909,7 +918,7 @@ def _meson_license(self) -> Optional[str]:
909918
assert isinstance(value, str)
910919
if value == 'unknown':
911920
return None
912-
return canonicalize_license_expression(value)
921+
return str(canonicalize_license_expression(value)) # str() is to make mypy happy
913922

914923
@property
915924
def _meson_license_files(self) -> Optional[List[pathlib.Path]]:

0 commit comments

Comments
 (0)