1 """The purpose of this module is implement PEP 621 validations that are
2 difficult to express as a JSON Schema (or that are not supported by the current
6 from typing import Mapping, TypeVar
8 from .error_reporting import ValidationError
10 T = TypeVar("T", bound=Mapping)
13 class RedefiningStaticFieldAsDynamic(ValidationError):
14 """According to PEP 621:
16 Build back-ends MUST raise an error if the metadata specifies a field
17 statically as well as being listed in dynamic.
21 def validate_project_dynamic(pyproject: T) -> T:
22 project_table = pyproject.get("project", {})
23 dynamic = project_table.get("dynamic", [])
26 if field in project_table:
27 msg = f"You cannot provide a value for `project.{field}` and "
28 msg += "list it under `project.dynamic` at the same time"
29 name = f"data.project.{field}"
30 value = {field: project_table[field], "...": " # ...", "dynamic": dynamic}
31 raise RedefiningStaticFieldAsDynamic(msg, value, name, rule="PEP 621")
36 EXTRA_VALIDATIONS = (validate_project_dynamic,)