create mode 100755 dts/generate-schema.py

Could it be worth putting this into devtools? It is a devtool.


diff --git a/doc/guides/tools/dts.rst b/doc/guides/tools/dts.rst

@@ -430,6 +430,16 @@ Refer to the script for usage: 
``devtools/dts-check-format.sh -h``.
  Configuration Schema
  --------------------
+The configuration schema is automatically generated from Pydantic models and can be found
+at ``dts/framework/config/conf_yaml_schema.json``. Whenever the models are 
changed, the schema
+should be regenerated using the dedicated script at 
``dts/generate-schema.py``, e.g.:

Should we add this to devtools/dts-check-format.sh? Looks like a good candidate.

+
+.. code-block:: console
+
+   $ poetry shell
+   (dts-py3.10) $ ./generate-schema.py
+
+
  Definitions
  ~~~~~~~~~~~

The definition names have changed and maybe there are also some other changes or does that not matter? Can these Pydantic changes help us with generating this schema description as well?

diff --git a/dts/generate-schema.py b/dts/generate-schema.py

@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2024 Arm Limited
+
+"""JSON schema generation script."""

This should at least say how to run the script, but we probably want to add more, such as from what it's creating the schema and where it's going to put it.


+from framework.config import ConfigurationType
+

Ah, so it is used elsewhere. Let's just rename it then.

+DTS_DIR = os.path.dirname(os.path.realpath(__file__))
+RELATIVE_PATH_TO_SCHEMA = "framework/config/conf_yaml_schema.json"

We're using pathlib everywhere in DTS, so let's use it here as well. Not sure if the portability is needed in this script, but why not.


+class GenerateSchemaWithDialect(GenerateJsonSchema):
+    """Custom schema generator which adds the schema dialect."""

I'd add that we're adding a reference to the schema dialect.


+    print("Schema generated successfully!")
+except Exception as e:
+    raise Exception("failed to generate schema") from e

Let's unify the message with the print above by capitalizing and adding a dot to the end.

Reply via email to