@@ -78,6 +78,8 @@ 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 ]))
82+ _SUPPORTED_DYNAMIC_FIELDS = {'version' , } if _PYPROJECT_METADATA_VERSION < (0 , 9 ) else {'version' , 'license' , 'license-files' }
8183
8284_NINJA_REQUIRED_VERSION = '1.8.2'
8385_MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml
@@ -244,6 +246,9 @@ class MesonBuilderError(Error):
244246
245247class Metadata (pyproject_metadata .StandardMetadata ):
246248 def __init__ (self , name : str , * args : Any , ** kwargs : Any ):
249+ if _PYPROJECT_METADATA_VERSION < (0 , 9 ):
250+ kwargs .pop ('license' , None )
251+ kwargs .pop ('license_files' , None )
247252 super ().__init__ (name , * args , ** kwargs )
248253 # Local fix for https://github.com/FFY00/python-pyproject-metadata/issues/60
249254 self .name = self ._validate_name (name )
@@ -272,7 +277,7 @@ def from_pyproject(
272277 'Required "project.version" field is missing and not declared as dynamic' )
273278
274279 # Check for unsupported dynamic fields.
275- unsupported_dynamic = set (metadata .dynamic ) - { 'version' , 'license' , 'license-files' }
280+ unsupported_dynamic = set (metadata .dynamic ) - _SUPPORTED_DYNAMIC_FIELDS
276281 if unsupported_dynamic :
277282 fields = ', ' .join (f'"{ x } "' for x in unsupported_dynamic )
278283 raise pyproject_metadata .ConfigurationError (f'Unsupported dynamic fields: { fields } ' )
@@ -759,7 +764,12 @@ def __init__(
759764 if license is None :
760765 raise pyproject_metadata .ConfigurationError (
761766 'Field "license" declared as dynamic but license is not specified in meson.build' )
762- self ._metadata .license = license
767+ # mypy is not happy when analyzing typing based on
768+ # pyproject-metadata < 0.9 where license needs to be of
769+ # License type. However, this code is not executed if
770+ # pyproject-metadata is older than 0.9 because then dynamic
771+ # license is not allowed.
772+ self ._metadata .license = license # type: ignore[assignment]
763773 if 'license-files' in self ._metadata .dynamic :
764774 self ._metadata .license_files = self ._meson_license_files
765775 else :
@@ -909,7 +919,7 @@ def _meson_license(self) -> Optional[str]:
909919 assert isinstance (value , str )
910920 if value == 'unknown' :
911921 return None
912- return canonicalize_license_expression (value )
922+ return str ( canonicalize_license_expression (value )) # str() is to make mypy happy
913923
914924 @property
915925 def _meson_license_files (self ) -> Optional [List [pathlib .Path ]]:
0 commit comments