Skip to content

Commit

Permalink
MAINT: refactor validation of meson introspection data
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Oct 12, 2024
1 parent 20a3413 commit 50dc31d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,14 +750,14 @@ def __init__(
# set version from meson.build if version is declared as dynamic
if 'version' in self._metadata.dynamic:
version = self._meson_version
if version == 'undefined':
if version is None:
raise pyproject_metadata.ConfigurationError(
'Field "version" declared as dynamic but version is not defined in meson.build')
self._metadata.version = packaging.version.Version(version)
else:
# if project section is missing, use minimal metdata from meson.build
name, version = self._meson_name, self._meson_version
if version == 'undefined':
if version is None:
raise pyproject_metadata.ConfigurationError(
'Section "project" missing in pyproject.toml and version is not defined in meson.build')
self._metadata = Metadata(name=name, version=packaging.version.Version(version))
Expand Down Expand Up @@ -871,17 +871,19 @@ def _manifest(self) -> DefaultDict[str, List[Tuple[pathlib.Path, str]]]:

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

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

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

0 comments on commit 50dc31d

Please sign in to comment.