@@ -78,6 +78,8 @@ def canonicalize_license_expression(s: str) -> str:
78
78
79
79
__version__ = '0.17.0.dev0'
80
80
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' }
81
83
82
84
_NINJA_REQUIRED_VERSION = '1.8.2'
83
85
_MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml
@@ -272,7 +274,7 @@ def from_pyproject(
272
274
'Required "project.version" field is missing and not declared as dynamic' )
273
275
274
276
# Check for unsupported dynamic fields.
275
- unsupported_dynamic = set (metadata .dynamic ) - { 'version' , 'license' , 'license-files' }
277
+ unsupported_dynamic = set (metadata .dynamic ) - _SUPPORTED_DYNAMIC_FIELDS
276
278
if unsupported_dynamic :
277
279
fields = ', ' .join (f'"{ x } "' for x in unsupported_dynamic )
278
280
raise pyproject_metadata .ConfigurationError (f'Unsupported dynamic fields: { fields } ' )
@@ -759,7 +761,12 @@ def __init__(
759
761
if license is None :
760
762
raise pyproject_metadata .ConfigurationError (
761
763
'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]
763
770
if 'license-files' in self ._metadata .dynamic :
764
771
self ._metadata .license_files = self ._meson_license_files
765
772
else :
@@ -768,9 +775,11 @@ def __init__(
768
775
if version is None :
769
776
raise pyproject_metadata .ConfigurationError (
770
777
'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 )
774
783
775
784
# verify that we are running on a supported interpreter
776
785
if self ._metadata .requires_python :
@@ -909,7 +918,7 @@ def _meson_license(self) -> Optional[str]:
909
918
assert isinstance (value , str )
910
919
if value == 'unknown' :
911
920
return None
912
- return canonicalize_license_expression (value )
921
+ return str ( canonicalize_license_expression (value )) # str() is to make mypy happy
913
922
914
923
@property
915
924
def _meson_license_files (self ) -> Optional [List [pathlib .Path ]]:
0 commit comments