|
56 | 56 |
|
57 | 57 |
|
58 | 58 | if typing.TYPE_CHECKING: # pragma: no cover
|
59 |
| - from typing import ( |
60 |
| - Any, Callable, ClassVar, DefaultDict, List, Literal, Optional, Sequence, TextIO, Tuple, Type, TypeVar, Union |
61 |
| - ) |
| 59 | + from typing import Any, Callable, DefaultDict, List, Literal, Optional, Sequence, TextIO, Tuple, Type, TypeVar, Union |
62 | 60 |
|
63 | 61 | from mesonpy._compat import Iterator, ParamSpec, Path
|
64 | 62 |
|
@@ -233,6 +231,12 @@ def from_pyproject(cls, data: Mapping[str, Any], project_dir: Path) -> Metadata:
|
233 | 231 | raise pyproject_metadata.ConfigurationError(
|
234 | 232 | 'Required "project.version" field is missing and not declared as dynamic')
|
235 | 233 |
|
| 234 | + # Check for unsupported dynamic fields. |
| 235 | + unsupported_dynamic = {key for key in metadata.dynamic if key not in {'version', }} |
| 236 | + if unsupported_dynamic: |
| 237 | + fields = ', '.join(f'"{x}"' for x in unsupported_dynamic) |
| 238 | + raise pyproject_metadata.ConfigurationError(f'Unsupported dynamic fields: {fields}') |
| 239 | + |
236 | 240 | return metadata # type: ignore[return-value]
|
237 | 241 |
|
238 | 242 | # Local fix for a bug in pyproject-metadata. See
|
@@ -641,11 +645,6 @@ def _string_or_strings(value: Any, name: str) -> List[str]:
|
641 | 645 | class Project():
|
642 | 646 | """Meson project wrapper to generate Python artifacts."""
|
643 | 647 |
|
644 |
| - _ALLOWED_DYNAMIC_FIELDS: ClassVar[List[str]] = [ |
645 |
| - 'version', |
646 |
| - ] |
647 |
| - _metadata: Metadata |
648 |
| - |
649 | 648 | def __init__( # noqa: C901
|
650 | 649 | self,
|
651 | 650 | source_dir: Path,
|
@@ -736,13 +735,20 @@ def __init__( # noqa: C901
|
736 | 735 | # package metadata
|
737 | 736 | if 'project' in pyproject:
|
738 | 737 | self._metadata = Metadata.from_pyproject(pyproject, self._source_dir)
|
| 738 | + # set version from meson.build if version is declared as dynamic |
| 739 | + if 'version' in self._metadata.dynamic: |
| 740 | + self._metadata.version = packaging.version.Version(self._meson_version) |
739 | 741 | else:
|
| 742 | + # if project section is missing, use minimal metdata from meson.build |
740 | 743 | self._metadata = Metadata(name=self._meson_name, version=packaging.version.Version(self._meson_version))
|
741 |
| - self._validate_metadata() |
742 | 744 |
|
743 |
| - # set version from meson.build if dynamic |
744 |
| - if 'version' in self._metadata.dynamic: |
745 |
| - self._metadata.version = packaging.version.Version(self._meson_version) |
| 745 | + # verify that we are running on a supported interpreter |
| 746 | + if self._metadata.requires_python: |
| 747 | + self._metadata.requires_python.prereleases = True |
| 748 | + if platform.python_version().rstrip('+') not in self._metadata.requires_python: |
| 749 | + raise MesonBuilderError( |
| 750 | + f'Package requires Python version {self._metadata.requires_python}, ' |
| 751 | + f'running on {platform.python_version()}') |
746 | 752 |
|
747 | 753 | # limited API
|
748 | 754 | self._limited_api = pyproject_config.get('limited-api', False)
|
@@ -784,27 +790,6 @@ def _configure(self, reconfigure: bool = False) -> None:
|
784 | 790 |
|
785 | 791 | self._run(['meson', 'setup', *setup_args])
|
786 | 792 |
|
787 |
| - def _validate_metadata(self) -> None: |
788 |
| - """Check the pyproject.toml metadata and see if there are any issues.""" |
789 |
| - |
790 |
| - # check for unsupported dynamic fields |
791 |
| - unsupported_dynamic = { |
792 |
| - key for key in self._metadata.dynamic |
793 |
| - if key not in self._ALLOWED_DYNAMIC_FIELDS |
794 |
| - } |
795 |
| - if unsupported_dynamic: |
796 |
| - s = ', '.join(f'"{x}"' for x in unsupported_dynamic) |
797 |
| - raise MesonBuilderError(f'Unsupported dynamic fields: {s}') |
798 |
| - |
799 |
| - # check if we are running on an unsupported interpreter |
800 |
| - if self._metadata.requires_python: |
801 |
| - self._metadata.requires_python.prereleases = True |
802 |
| - if platform.python_version().rstrip('+') not in self._metadata.requires_python: |
803 |
| - raise MesonBuilderError( |
804 |
| - f'Unsupported Python version {platform.python_version()}, ' |
805 |
| - f'expected {self._metadata.requires_python}' |
806 |
| - ) |
807 |
| - |
808 | 793 | @cached_property
|
809 | 794 | def _wheel_builder(self) -> _WheelBuilder:
|
810 | 795 | return _WheelBuilder(
|
|
0 commit comments