@@ -748,20 +748,6 @@ def __init__( # noqa: C901
748
748
# load pyproject.toml
749
749
pyproject = tomllib .loads (self ._source_dir .joinpath ('pyproject.toml' ).read_text ())
750
750
751
- # package metadata
752
- self ._pep621 = 'project' in pyproject :
753
- if self .pep621 :
754
- self ._metadata = pyproject_metadata .StandardMetadata .from_pyproject (pyproject , self ._source_dir )
755
- else :
756
- print (
757
- '{yellow}{bold}! Using Meson to generate the project metadata '
758
- '(no `project` section in pyproject.toml){reset}' .format (** _STYLES )
759
- )
760
- self ._metadata = None
761
-
762
- if self ._metadata :
763
- self ._validate_metadata ()
764
-
765
751
# load meson args from pyproject.toml
766
752
pyproject_config = _validate_pyproject_config (pyproject )
767
753
for key , value in pyproject_config .get ('args' , {}).items ():
@@ -802,9 +788,20 @@ def __init__( # noqa: C901
802
788
has_valid_build_dir = self ._build_dir .joinpath ('meson-private' , 'coredata.dat' ).is_file ()
803
789
self ._configure (reconfigure = has_valid_build_dir and not native_file_mismatch )
804
790
805
- # set version if dynamic (this fetches it from Meson)
806
- if self ._metadata and 'version' in self ._metadata .dynamic :
807
- self ._metadata .version = self .version
791
+ # package metadata
792
+ if 'project' in pyproject :
793
+ self ._metadata = pyproject_metadata .StandardMetadata .from_pyproject (pyproject , self ._source_dir )
794
+ else :
795
+ self ._metadata = pyproject_metadata .StandardMetadata (name = self ._meson_name , version = self ._meson_version )
796
+ print (
797
+ '{yellow}{bold}! Using Meson to generate the project metadata '
798
+ '(no `project` section in pyproject.toml){reset}' .format (** _STYLES )
799
+ )
800
+ self ._validate_metadata ()
801
+
802
+ # set version from meson.build if dynamic
803
+ if 'version' in self ._metadata .dynamic :
804
+ self ._metadata .version = self ._meson_version
808
805
809
806
def _proc (self , * args : str ) -> None :
810
807
"""Invoke a subprocess."""
@@ -858,8 +855,6 @@ def _configure(self, reconfigure: bool = False) -> None:
858
855
def _validate_metadata (self ) -> None :
859
856
"""Check the pyproject.toml metadata and see if there are any issues."""
860
857
861
- assert self ._metadata
862
-
863
858
# check for unsupported dynamic fields
864
859
unsupported_dynamic = {
865
860
key for key in self ._metadata .dynamic
@@ -991,45 +986,18 @@ def _meson_version(self) -> str:
991
986
992
987
@property
993
988
def name (self ) -> str :
994
- """Project name. Specified in pyproject.toml."""
995
- name = self ._metadata .name if self ._metadata else self ._meson_name
996
- assert isinstance (name , str )
997
- return name .replace ('-' , '_' )
989
+ """Project name."""
990
+ return self ._metadata .name .replace ('-' , '_' )
998
991
999
992
@property
1000
993
def version (self ) -> str :
1001
- """Project version. Either specified in pyproject.toml or meson.build."""
1002
- if self ._metadata and 'version' not in self ._metadata .dynamic :
1003
- version = str (self ._metadata .version )
1004
- else :
1005
- version = self ._meson_version
1006
- assert isinstance (version , str )
1007
- return version
994
+ """Project version."""
995
+ return str (self ._metadata .version )
1008
996
1009
997
@cached_property
1010
998
def metadata (self ) -> bytes :
1011
- """Project metadata."""
1012
- # the rest of the keys are only available when using PEP 621 metadata
1013
- if not self .pep621 :
1014
- data = textwrap .dedent (f'''
1015
- Metadata-Version: 2.1
1016
- Name: { self .name }
1017
- Version: { self .version }
1018
- ''' ).strip ()
1019
- return data .encode ()
1020
-
1021
- # re-import pyproject_metadata to raise ModuleNotFoundError if it is really missing
1022
- import pyproject_metadata # noqa: F401
1023
- assert self ._metadata
1024
-
1025
- core_metadata = self ._metadata .as_rfc822 ()
1026
- # use self.version as the version may be dynamic -- fetched from Meson
1027
- #
1028
- # we need to overwrite this field in the RFC822 field as
1029
- # pyproject_metadata removes 'version' from the dynamic fields when
1030
- # giving it a value via the dataclass
1031
- core_metadata .headers ['Version' ] = [self .version ]
1032
- return bytes (core_metadata )
999
+ """Project metadata as an RFC822 message."""
1000
+ return bytes (self ._metadata .as_rfc822 ())
1033
1001
1034
1002
@property
1035
1003
def license_file (self ) -> Optional [pathlib .Path ]:
@@ -1044,11 +1012,6 @@ def is_pure(self) -> bool:
1044
1012
"""Is the wheel "pure" (architecture independent)?"""
1045
1013
return bool (self ._wheel_builder .is_pure )
1046
1014
1047
- @property
1048
- def pep621 (self ) -> bool :
1049
- """Does the project use PEP 621 metadata?"""
1050
- return self ._pep621
1051
-
1052
1015
def sdist (self , directory : Path ) -> pathlib .Path :
1053
1016
"""Generates a sdist (source distribution) in the specified directory."""
1054
1017
# generate meson dist file
0 commit comments