Repository: scikit-build/scikit-build-core
Pull request #522 (2023-10-06 21:53:32)

fix(schema): a typo and better metadata support
Noticed when working on submitting to SchemaStore.



Patch:
diff --git a/src/scikit_build_core/resources/scikit-build.schema.json b/src/scikit_build_core/resources/scikit-build.schema.json
index bef0f0e..6ff309f 100644
--- a/src/scikit_build_core/resources/scikit-build.schema.json
+++ b/src/scikit_build_core/resources/scikit-build.schema.json
@@ -278,12 +278,55 @@
     },
     "metadata": {
       "type": "object",
-      "patternProperties": {
-        ".+": {
-          "type": "object"
+      "description": "List dynamic metadata fields and hook locations in this table.",
+      "additionalProperties": false,
+      "properties": {
+        "version": {
+          "$ref": "#/$defs/metadata"
+        },
+        "description": {
+          "$ref": "#/$defs/metadata"
+        },
+        "license": {
+          "$ref": "#/$defs/metadata"
+        },
+        "readme": {
+          "$ref": "#/$defs/metadata"
+        },
+        "requires-python": {
+          "$ref": "#/$defs/metadata"
+        },
+        "dependencies": {
+          "$ref": "#/$defs/metadata"
+        },
+        "optional-dependencies": {
+          "$ref": "#/$defs/metadata"
+        },
+        "entrypoints": {
+          "$ref": "#/$defs/metadata"
+        },
+        "authors": {
+          "$ref": "#/$defs/metadata"
+        },
+        "maintainers": {
+          "$ref": "#/$defs/metadata"
+        },
+        "urls": {
+          "$ref": "#/$defs/metadata"
+        },
+        "classifiers": {
+          "$ref": "#/$defs/metadata"
+        },
+        "keywords": {
+          "$ref": "#/$defs/metadata"
+        },
+        "scripts": {
+          "$ref": "#/$defs/metadata"
+        },
+        "gui-scripts": {
+          "$ref": "#/$defs/metadata"
         }
-      },
-      "description": "List dynamic metadata fields and hook locations in this table."
+      }
     },
     "strict-config": {
       "type": "boolean",
@@ -307,7 +350,7 @@
     "overrides": {
       "type": "array",
       "items": {
-        "type: ": "object",
+        "type": "object",
         "required": [
           "if"
         ],
@@ -381,5 +424,18 @@
         }
       }
     }
+  },
+  "$defs": {
+    "metadata": {
+      "type": "object",
+      "properties": {
+        "provider": {
+          "type": "string"
+        },
+        "provider-path": {
+          "type": "string"
+        }
+      }
+    }
   }
 }
diff --git a/src/scikit_build_core/settings/skbuild_schema.py b/src/scikit_build_core/settings/skbuild_schema.py
index 77899b9..b24fb91 100644
--- a/src/scikit_build_core/settings/skbuild_schema.py
+++ b/src/scikit_build_core/settings/skbuild_schema.py
@@ -13,6 +13,25 @@ def __dir__() -> list[str]:
     return __all__
 
 
+METADATA = [
+    "version",
+    "description",
+    "license",
+    "readme",
+    "requires-python",
+    "dependencies",
+    "optional-dependencies",
+    "entrypoints",
+    "authors",
+    "maintainers",
+    "urls",
+    "classifiers",
+    "keywords",
+    "scripts",
+    "gui-scripts",
+]
+
+
 def generate_skbuild_schema(tool_name: str = "scikit-build") -> dict[str, Any]:
     "Generate the complete schema for scikit-build settings."
     assert tool_name == "scikit-build", "Only scikit-build is supported."
@@ -47,11 +66,27 @@ def generate_skbuild_schema(tool_name: str = "scikit-build") -> dict[str, Any]:
         "oneOf": [generate_tmpl, generate_path]
     }
 
+    schema["$defs"] = {
+        "metadata": {
+            "type": "object",
+            "properties": {
+                "provider": {"type": "string"},
+                "provider-path": {"type": "string"},
+            },
+        }
+    }
+
+    del schema["properties"]["metadata"]["patternProperties"]
+    schema["properties"]["metadata"]["additionalProperties"] = False
+    schema["properties"]["metadata"]["properties"] = {
+        m: {"$ref": "#/$defs/metadata"} for m in METADATA
+    }
+
     props = {k: {"$ref": f"#/properties/{k}"} for k in schema["properties"]}
     schema["properties"]["overrides"] = {
         "type": "array",
         "items": {
-            "type: ": "object",
+            "type": "object",
             "required": ["if"],
             "minProperties": 2,
             "additionalProperties": False,


Test patch:
diff --git a/tests/test_schema.py b/tests/test_schema.py
index d05b797..899030e 100644
--- a/tests/test_schema.py
+++ b/tests/test_schema.py
@@ -58,6 +58,9 @@ def test_valid_schemas_files(filepath: Path) -> None:
                 }
             ]
         },
+        {"metadata": {"version": {"provider-path": True}}},
+        {"metadata": {"version": {"provider": 2}}},
+        {"metadata": {"invalid": {"provider": "correct"}}},
     ],
 )
 def test_invalid_schemas(addition: dict[str, Any]) -> None:
@@ -77,6 +80,7 @@ def test_invalid_schemas(addition: dict[str, Any]) -> None:
     example["tool"]["scikit-build"].update(**addition)
 
     validator = api.Validator()
+    print(example)
     with pytest.raises(fastjsonschema.JsonSchemaValueException):
         validator(example)
 
@@ -94,6 +98,8 @@ def test_invalid_schemas(addition: dict[str, Any]) -> None:
                 }
             ]
         },
+        {"metadata": {"version": {"provider-path": "string"}}},
+        {"metadata": {"description": {"anything": True}}},
     ],
 )
 def test_valid_schemas(addition: dict[str, Any]) -> None: