diff --git a/mesonpy/__init__.py b/mesonpy/__init__.py index 1acc639b..c66e91fb 100644 --- a/mesonpy/__init__.py +++ b/mesonpy/__init__.py @@ -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)) @@ -848,17 +848,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.""" @@ -866,7 +868,8 @@ def sdist(self, directory: Path) -> pathlib.Path: 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