Skip to content

Commit fa7f95b

Browse files
committed
MAINT: refactor validation of meson introspection data
1 parent eb8dae8 commit fa7f95b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

mesonpy/__init__.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -749,14 +749,14 @@ def __init__(
749749
# set version from meson.build if version is declared as dynamic
750750
if 'version' in self._metadata.dynamic:
751751
version = self._meson_version
752-
if version == 'undefined':
752+
if version is None:
753753
raise pyproject_metadata.ConfigurationError(
754754
'Field "version" declared as dynamic but version is not defined in meson.build')
755755
self._metadata.version = packaging.version.Version(version)
756756
else:
757757
# if project section is missing, use minimal metdata from meson.build
758758
name, version = self._meson_name, self._meson_version
759-
if version == 'undefined':
759+
if version is None:
760760
raise pyproject_metadata.ConfigurationError(
761761
'Section "project" missing in pyproject.toml and version is not defined in meson.build')
762762
self._metadata = Metadata(name=name, version=packaging.version.Version(version))
@@ -870,17 +870,19 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:
870870

871871
@property
872872
def _meson_name(self) -> str:
873-
"""Name in meson.build."""
874-
name = self._info('intro-projectinfo')['descriptive_name']
875-
assert isinstance(name, str)
876-
return name
873+
"""The project name specified with ``project()`` in meson.build."""
874+
value = self._info('intro-projectinfo')['descriptive_name']
875+
assert isinstance(value, str)
876+
return value
877877

878878
@property
879-
def _meson_version(self) -> str:
880-
"""Version in meson.build."""
881-
name = self._info('intro-projectinfo')['version']
882-
assert isinstance(name, str)
883-
return name
879+
def _meson_version(self) -> Optional[str]:
880+
"""The version specified with the ``version`` argument to ``project()`` in meson.build."""
881+
value = self._info('intro-projectinfo')['version']
882+
assert isinstance(value, str)
883+
if value == 'undefined':
884+
return None
885+
return value
884886

885887
def sdist(self, directory: Path) -> pathlib.Path:
886888
"""Generates a sdist (source distribution) in the specified directory."""

0 commit comments

Comments
 (0)