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 Nov 19, 2024
1 parent 6ee1b7f commit cf737ff
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,14 +727,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 not version:
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 @@ -848,25 +848,28 @@ 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."""
# Generate meson dist file.
self._run(self._meson + ['dist', '--allow-dirty', '--no-tests', '--formats', 'gztar', *self._meson_args['dist']])

dist_name = f'{self._metadata.distribution_name}-{self._metadata.version}'
meson_dist_name = f'{self._meson_name}-{self._meson_version}'
meson_version = self._meson_version or 'undefined'
meson_dist_name = f'{self._meson_name}-{meson_version}'
meson_dist_path = pathlib.Path(self._build_dir, 'meson-dist', f'{meson_dist_name}.tar.gz')
sdist_path = pathlib.Path(directory, f'{dist_name}.tar.gz')
pyproject_toml_mtime = 0
Expand Down

0 comments on commit cf737ff

Please sign in to comment.