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 430d5eb commit bc25261
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ def canonicalize_license_expression(s: str) -> str:

__version__ = '0.17.0.dev0'

_PYPROJECT_METADATA_VERSION = tuple(map(int, pyproject_metadata.__version__.split('.')[:2]))

_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 @@ -244,6 +245,9 @@ class MesonBuilderError(Error):

class Metadata(pyproject_metadata.StandardMetadata):
def __init__(self, name: str, *args: Any, **kwargs: Any):
if _PYPROJECT_METADATA_VERSION < (0, 9):
kwargs.pop('license', None)
kwargs.pop('license_files', None)
super().__init__(name, *args, **kwargs)
# Local fix for https:/FFY00/python-pyproject-metadata/issues/60
self.name = self._validate_name(name)
Expand Down Expand Up @@ -758,7 +762,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 Down Expand Up @@ -908,7 +917,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) -> List[pathlib.Path]:
Expand Down

0 comments on commit bc25261

Please sign in to comment.