Skip to content

Commit fa4cfc5

Browse files
committed
MAINT: refactor validation of meson introspection data
1 parent e3ced25 commit fa4cfc5

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

mesonpy/__init__.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,14 @@ def __init__(
727727
# set version from meson.build if version is declared as dynamic
728728
if 'version' in self._metadata.dynamic:
729729
version = self._meson_version
730-
if version == 'undefined':
730+
if version is None:
731731
raise pyproject_metadata.ConfigurationError(
732732
'Field "version" declared as dynamic but version is not defined in meson.build')
733733
self._metadata.version = packaging.version.Version(version)
734734
else:
735735
# if project section is missing, use minimal metdata from meson.build
736736
name, version = self._meson_name, self._meson_version
737-
if version == 'undefined':
737+
if not version:
738738
raise pyproject_metadata.ConfigurationError(
739739
'Section "project" missing in pyproject.toml and version is not defined in meson.build')
740740
self._metadata = Metadata(name=name, version=packaging.version.Version(version))
@@ -848,25 +848,28 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:
848848

849849
@property
850850
def _meson_name(self) -> str:
851-
"""Name in meson.build."""
852-
name = self._info('intro-projectinfo')['descriptive_name']
853-
assert isinstance(name, str)
854-
return name
851+
"""The project name specified with ``project()`` in meson.build."""
852+
value = self._info('intro-projectinfo')['descriptive_name']
853+
assert isinstance(value, str)
854+
return value
855855

856856
@property
857-
def _meson_version(self) -> str:
858-
"""Version in meson.build."""
859-
name = self._info('intro-projectinfo')['version']
860-
assert isinstance(name, str)
861-
return name
857+
def _meson_version(self) -> Optional[str]:
858+
"""The version specified with the ``version`` argument to ``project()`` in meson.build."""
859+
value = self._info('intro-projectinfo')['version']
860+
assert isinstance(value, str)
861+
if value == 'undefined':
862+
return None
863+
return value
862864

863865
def sdist(self, directory: Path) -> pathlib.Path:
864866
"""Generates a sdist (source distribution) in the specified directory."""
865867
# Generate meson dist file.
866868
self._run(self._meson + ['dist', '--allow-dirty', '--no-tests', '--formats', 'gztar', *self._meson_args['dist']])
867869

868870
dist_name = f'{self._metadata.distribution_name}-{self._metadata.version}'
869-
meson_dist_name = f'{self._meson_name}-{self._meson_version}'
871+
meson_version = self._meson_version or 'undefined'
872+
meson_dist_name = f'{self._meson_name}-{meson_version}'
870873
meson_dist_path = pathlib.Path(self._build_dir, 'meson-dist', f'{meson_dist_name}.tar.gz')
871874
sdist_path = pathlib.Path(directory, f'{dist_name}.tar.gz')
872875
pyproject_toml_mtime = 0

0 commit comments

Comments
 (0)