| 1 |
"""Write the base JSON Schema for a config file into the package. |
| 2 |
|
| 3 |
`hsql --config schema` generates a schema for the machine it runs on, adapters |
| 4 |
and all. The file this writes is the other one: the same document built for no |
| 5 |
adapters, so it describes the config format rather than an installation, and it |
| 6 |
is what harlequin.sh publishes at the `$id` it carries. |
| 7 |
|
| 8 |
Usage: |
| 9 |
uv run python scripts/write_config_schema.py |
| 10 |
|
| 11 |
`tests/unit_tests/test_config_schema.py` is what fails when the file and the |
| 12 |
generator disagree, which is any change to the config model, to hsql's own |
| 13 |
options, or to what either describes. |
| 14 |
""" |
| 15 |
|
| 16 |
from __future__ import annotations |
| 17 |
|
| 18 |
import json |
| 19 |
from pathlib import Path |
| 20 |
|
| 21 |
from harlequin.config_schema import build_schema |
| 22 |
from harlequin.hsql.cli import bare_command |
| 23 |
|
| 24 |
BASE_SCHEMA_PATH = ( |
| 25 |
Path(__file__).resolve().parents[1] |
| 26 |
/ "src" |
| 27 |
/ "harlequin" |
| 28 |
/ "schemas" |
| 29 |
/ "config-v1.json" |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
def main() -> None: |
| 34 |
BASE_SCHEMA_PATH.parent.mkdir(parents=True, exist_ok=True) |
| 35 |
document = build_schema(bare_command().params, adapters=None) |
| 36 |
BASE_SCHEMA_PATH.write_text( |
| 37 |
json.dumps(document, indent=2) + "\n", encoding="utf-8", newline="\n" |
| 38 |
) |
| 39 |
print(f"wrote {BASE_SCHEMA_PATH}") |
| 40 |
|
| 41 |
|
| 42 |
if __name__ == "__main__": |
| 43 |
main() |