@@ -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 
@@ -272,7 +274,7 @@ def from_pyproject(
272274                'Required "project.version" field is missing and not declared as dynamic' )
273275
274276        # Check for unsupported dynamic fields. 
275-         unsupported_dynamic  =  set (metadata .dynamic ) -  { 'version' ,  'license' ,  'license-files' } 
277+         unsupported_dynamic  =  set (metadata .dynamic ) -  _SUPPORTED_DYNAMIC_FIELDS 
276278        if  unsupported_dynamic :
277279            fields  =  ', ' .join (f'"{ x }  "'  for  x  in  unsupported_dynamic )
278280            raise  pyproject_metadata .ConfigurationError (f'Unsupported dynamic fields: { fields }  ' )
@@ -759,7 +761,12 @@ def __init__(
759761                if  license  is  None :
760762                    raise  pyproject_metadata .ConfigurationError (
761763                        'Field "license" declared as dynamic but license is not specified in meson.build' )
762-                 self ._metadata .license  =  license 
764+                 # mypy is not happy when analyzing typing based on 
765+                 # pyproject-metadata < 0.9 where license needs to be of 
766+                 # License type.  However, this code is not executed if 
767+                 # pyproject-metadata is older than 0.9 because then dynamic 
768+                 # license is not allowed. 
769+                 self ._metadata .license  =  license   # type: ignore[assignment] 
763770            if  'license-files'  in  self ._metadata .dynamic :
764771                self ._metadata .license_files  =  self ._meson_license_files 
765772        else :
@@ -768,9 +775,11 @@ def __init__(
768775            if  version  is  None :
769776                raise  pyproject_metadata .ConfigurationError (
770777                    'Section "project" missing in pyproject.toml and version is not defined in meson.build' )
771-             self ._metadata  =  Metadata (
772-                 name = name , version = packaging .version .Version (version ),
773-                 license = self ._meson_license , license_files = self ._meson_license_files )
778+             kwargs  =  {
779+                 'license' : self ._meson_license ,
780+                 'license_files' : self ._meson_license_files 
781+             } if  _PYPROJECT_METADATA_VERSION  >=  (0 , 9 ) else  {}
782+             self ._metadata  =  Metadata (name = name , version = packaging .version .Version (version ), ** kwargs )
774783
775784        # verify that we are running on a supported interpreter 
776785        if  self ._metadata .requires_python :
@@ -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