Skip to content

Commit

Permalink
BUG: adjust to older pyproject-metadata releases
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Oct 12, 2024
1 parent 017bbdd commit 8609c36
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def canonicalize_license_expression(s: str) -> str:

__version__ = '0.17.0.dev0'

_PYPROJECT_METADATA_VERSION = tuple(map(int, pyproject_metadata.__version__.split('.')[:2]))
_SUPPORTED_DYNAMIC_FIELDS = {'version', } if _PYPROJECT_METADATA_VERSION < (0, 9) else {'version', 'license', 'license-files'}

_NINJA_REQUIRED_VERSION = '1.8.2'
_MESON_REQUIRED_VERSION = '0.63.3' # keep in sync with the version requirement in pyproject.toml
Expand Down Expand Up @@ -272,7 +274,7 @@ def from_pyproject(
'Required "project.version" field is missing and not declared as dynamic')

# Check for unsupported dynamic fields.
unsupported_dynamic = set(metadata.dynamic) - {'version', 'license', 'license-files'}
unsupported_dynamic = set(metadata.dynamic) - _SUPPORTED_DYNAMIC_FIELDS
if unsupported_dynamic:
fields = ', '.join(f'"{x}"' for x in unsupported_dynamic)
raise pyproject_metadata.ConfigurationError(f'Unsupported dynamic fields: {fields}')
Expand Down Expand Up @@ -759,7 +761,12 @@ def __init__(
if license is None:
raise pyproject_metadata.ConfigurationError(
'Field "license" declared as dynamic but license is not specified in meson.build')
self._metadata.license = license
# mypy is not happy when analyzing typing based on
# pyproject-metadata < 0.9 where license needs to be of
# License type. However, this code is not executed if
# pyproject-metadata is older than 0.9 because then dynamic
# license is not allowed.
self._metadata.license = license # type: ignore[assignment]
if 'license-files' in self._metadata.dynamic:
self._metadata.license_files = self._meson_license_files
else:
Expand All @@ -768,9 +775,11 @@ def __init__(
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),
license=self._meson_license, license_files=self._meson_license_files)
kwargs = {
'license': self._meson_license,
'license_files': self._meson_license_files
} if _PYPROJECT_METADATA_VERSION >= (0, 9) else {}
self._metadata = Metadata(name=name, version=packaging.version.Version(version), **kwargs)

# verify that we are running on a supported interpreter
if self._metadata.requires_python:
Expand Down Expand Up @@ -909,7 +918,7 @@ def _meson_license(self) -> Optional[str]:
assert isinstance(value, str)
if value == 'unknown':
return None
return canonicalize_license_expression(value)
return str(canonicalize_license_expression(value)) # str() is to make mypy happy

@property
def _meson_license_files(self) -> Optional[List[pathlib.Path]]:
Expand Down

0 comments on commit 8609c36

Please sign in to comment.