@@ -219,13 +219,36 @@ class MesonBuilderError(Error):
219
219
"""Error when building the Meson package."""
220
220
221
221
222
+ class Metadata (pyproject_metadata .StandardMetadata ):
223
+ # The class method from the pyproject_metadata base class is not
224
+ # typed in a subclassing friendly way, thus annotations to ignore
225
+ # typing are needed.
226
+
227
+ @classmethod
228
+ def from_pyproject (cls , data : Mapping [str , Any ], project_dir : Path ) -> Metadata : # type: ignore[override]
229
+ metadata = super ().from_pyproject (data , project_dir )
230
+
231
+ # Check for missing version field.
232
+ if not metadata .version and 'version' not in metadata .dynamic :
233
+ raise pyproject_metadata .ConfigurationError (
234
+ 'Required "project.version" field is missing and not declared as dynamic' )
235
+
236
+ return metadata # type: ignore[return-value]
237
+
238
+ # Local fix for a bug in pyproject-metadata. See
239
+ # https://github.com/mesonbuild/meson-python/issues/454
240
+ def _update_dynamic (self , value : Any ) -> None :
241
+ if value and 'version' in self .dynamic :
242
+ self .dynamic .remove ('version' )
243
+
244
+
222
245
class _WheelBuilder ():
223
246
"""Helper class to build wheels from projects."""
224
247
225
248
def __init__ (
226
249
self ,
227
250
project : Project ,
228
- metadata : Optional [pyproject_metadata . StandardMetadata ],
251
+ metadata : Optional [Metadata ],
229
252
source_dir : pathlib .Path ,
230
253
build_dir : pathlib .Path ,
231
254
sources : Dict [str , Dict [str , Any ]],
@@ -621,7 +644,7 @@ class Project():
621
644
_ALLOWED_DYNAMIC_FIELDS : ClassVar [List [str ]] = [
622
645
'version' ,
623
646
]
624
- _metadata : pyproject_metadata . StandardMetadata
647
+ _metadata : Metadata
625
648
626
649
def __init__ ( # noqa: C901
627
650
self ,
@@ -712,10 +735,9 @@ def __init__( # noqa: C901
712
735
713
736
# package metadata
714
737
if 'project' in pyproject :
715
- self ._metadata = pyproject_metadata . StandardMetadata .from_pyproject (pyproject , self ._source_dir )
738
+ self ._metadata = Metadata .from_pyproject (pyproject , self ._source_dir )
716
739
else :
717
- self ._metadata = pyproject_metadata .StandardMetadata (
718
- name = self ._meson_name , version = packaging .version .Version (self ._meson_version ))
740
+ self ._metadata = Metadata (name = self ._meson_name , version = packaging .version .Version (self ._meson_version ))
719
741
self ._validate_metadata ()
720
742
721
743
# set version from meson.build if dynamic
0 commit comments