@@ -748,20 +748,6 @@ def __init__( # noqa: C901
748748 # load pyproject.toml
749749 pyproject = tomllib .loads (self ._source_dir .joinpath ('pyproject.toml' ).read_text ())
750750
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-
765751 # load meson args from pyproject.toml
766752 pyproject_config = _validate_pyproject_config (pyproject )
767753 for key , value in pyproject_config .get ('args' , {}).items ():
@@ -802,9 +788,20 @@ def __init__( # noqa: C901
802788 has_valid_build_dir = self ._build_dir .joinpath ('meson-private' , 'coredata.dat' ).is_file ()
803789 self ._configure (reconfigure = has_valid_build_dir and not native_file_mismatch )
804790
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
808805
809806 def _proc (self , * args : str ) -> None :
810807 """Invoke a subprocess."""
@@ -858,8 +855,6 @@ def _configure(self, reconfigure: bool = False) -> None:
858855 def _validate_metadata (self ) -> None :
859856 """Check the pyproject.toml metadata and see if there are any issues."""
860857
861- assert self ._metadata
862-
863858 # check for unsupported dynamic fields
864859 unsupported_dynamic = {
865860 key for key in self ._metadata .dynamic
@@ -991,45 +986,18 @@ def _meson_version(self) -> str:
991986
992987 @property
993988 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 ('-' , '_' )
998991
999992 @property
1000993 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 )
1008996
1009997 @cached_property
1010998 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 ())
10331001
10341002 @property
10351003 def license_file (self ) -> Optional [pathlib .Path ]:
@@ -1044,11 +1012,6 @@ def is_pure(self) -> bool:
10441012 """Is the wheel "pure" (architecture independent)?"""
10451013 return bool (self ._wheel_builder .is_pure )
10461014
1047- @property
1048- def pep621 (self ) -> bool :
1049- """Does the project use PEP 621 metadata?"""
1050- return self ._pep621
1051-
10521015 def sdist (self , directory : Path ) -> pathlib .Path :
10531016 """Generates a sdist (source distribution) in the specified directory."""
10541017 # generate meson dist file
0 commit comments