|
57 | 57 |
|
58 | 58 |
|
59 | 59 | if typing.TYPE_CHECKING: # pragma: no cover
|
60 |
| - from typing import ( |
61 |
| - Any, Callable, ClassVar, DefaultDict, List, Literal, Optional, Sequence, TextIO, Tuple, Type, TypeVar, Union |
62 |
| - ) |
| 60 | + from typing import Any, Callable, DefaultDict, List, Literal, Optional, Sequence, TextIO, Tuple, Type, TypeVar, Union |
63 | 61 |
|
64 | 62 | from mesonpy._compat import Iterator, ParamSpec, Path
|
65 | 63 |
|
@@ -618,13 +616,28 @@ def _string_or_strings(value: Any, name: str) -> List[str]:
|
618 | 616 | return config
|
619 | 617 |
|
620 | 618 |
|
621 |
| -class Project(): |
622 |
| - """Meson project wrapper to generate Python artifacts.""" |
| 619 | +def _validate_metadata(metadata: pyproject_metadata.StandardMetadata) -> None: |
| 620 | + """Validate package metadata.""" |
623 | 621 |
|
624 |
| - _ALLOWED_DYNAMIC_FIELDS: ClassVar[List[str]] = [ |
| 622 | + allowed_dynamic_fields = [ |
625 | 623 | 'version',
|
626 | 624 | ]
|
627 | 625 |
|
| 626 | + # check for unsupported dynamic fields |
| 627 | + unsupported_dynamic = {key for key in metadata.dynamic if key not in allowed_dynamic_fields} |
| 628 | + if unsupported_dynamic: |
| 629 | + s = ', '.join(f'"{x}"' for x in unsupported_dynamic) |
| 630 | + raise ConfigError(f'unsupported dynamic metadata fields: {s}') |
| 631 | + |
| 632 | + # check if we are running on an unsupported interpreter |
| 633 | + if metadata.requires_python: |
| 634 | + metadata.requires_python.prereleases = True |
| 635 | + if platform.python_version().rstrip('+') not in metadata.requires_python: |
| 636 | + raise ConfigError(f'building with Python {platform.python_version()}, version {metadata.requires_python} required') |
| 637 | + |
| 638 | + |
| 639 | +class Project(): |
| 640 | + """Meson project wrapper to generate Python artifacts.""" |
628 | 641 | def __init__(
|
629 | 642 | self,
|
630 | 643 | source_dir: Path,
|
@@ -722,7 +735,7 @@ def __init__(
|
722 | 735 | '{yellow}{bold}! Using Meson to generate the project metadata '
|
723 | 736 | '(no `project` section in pyproject.toml){reset}'.format(**_STYLES)
|
724 | 737 | )
|
725 |
| - self._validate_metadata() |
| 738 | + _validate_metadata(self._metadata) |
726 | 739 |
|
727 | 740 | # set version from meson.build if dynamic
|
728 | 741 | if 'version' in self._metadata.dynamic:
|
@@ -764,27 +777,6 @@ def _configure(self, reconfigure: bool = False) -> None:
|
764 | 777 |
|
765 | 778 | self._run(['meson', 'setup', *setup_args])
|
766 | 779 |
|
767 |
| - def _validate_metadata(self) -> None: |
768 |
| - """Check the pyproject.toml metadata and see if there are any issues.""" |
769 |
| - |
770 |
| - # check for unsupported dynamic fields |
771 |
| - unsupported_dynamic = { |
772 |
| - key for key in self._metadata.dynamic |
773 |
| - if key not in self._ALLOWED_DYNAMIC_FIELDS |
774 |
| - } |
775 |
| - if unsupported_dynamic: |
776 |
| - s = ', '.join(f'"{x}"' for x in unsupported_dynamic) |
777 |
| - raise MesonBuilderError(f'Unsupported dynamic fields: {s}') |
778 |
| - |
779 |
| - # check if we are running on an unsupported interpreter |
780 |
| - if self._metadata.requires_python: |
781 |
| - self._metadata.requires_python.prereleases = True |
782 |
| - if platform.python_version().rstrip('+') not in self._metadata.requires_python: |
783 |
| - raise MesonBuilderError( |
784 |
| - f'Unsupported Python version {platform.python_version()}, ' |
785 |
| - f'expected {self._metadata.requires_python}' |
786 |
| - ) |
787 |
| - |
788 | 780 | @cached_property
|
789 | 781 | def _wheel_builder(self) -> _WheelBuilder:
|
790 | 782 | return _WheelBuilder(
|
|
0 commit comments