scripts.domaingen

Reference › scripts › domaingen

The command-line interface for SPEC-105, ontology-driven domain-model generation. It is a thin wrapper over the domaingen package (see also the domaingen module narrative). No test imports it.

Invocation: --ontology (required) is the path to a .ttl ontology file, --out is the directory for generated code, and --render-ttl prints the ontology re-rendered from the intermediate model, as a round-trip check, and exits. main parses the ontology with parse_ontology, reports on standard error how many entities and modules it found, then either renders it with render_ontology or writes code with generate_code and prints the path of each generated file. Without --render-ttl, --out is required.

At a glance

Source scripts/domaingen.py
Lines of code 58
Classes 0
Functions 1
Imports (internal) orchestrata_ultimate.domaingen
Imported by none
Tests that import it none

Class diagram

No classes; see Functions.

Dependency diagram

Dependency diagram scripts.domaingen

API

Functions

Function Signature Summary
main main() -> int

Source

Permalink: https://gitlab.com/MSamy/orchestrata-ultimate-architecture/-/blob/a4cbc2bdf/scripts/domaingen.py

#!/usr/bin/env python3
"""CLI for SPEC-105 ontology-driven domain model generation.

Read an OWL/Turtle ontology and generate a screaming-architecture domain model
(entities + temporal insert-only Stardog repositories); optionally re-render the
ontology from the IR to verify the round-trip.

    python scripts/domaingen.py --ontology ontology.ttl --out build/domain
    python scripts/domaingen.py --ontology ontology.ttl --render-ttl   # IR -> TTL to stdout
"""

import argparse
import sys
from pathlib import Path

_REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
    sys.path.insert(0, str(_REPO_ROOT))


def main() -> int:
    ap = argparse.ArgumentParser(description=__doc__)
    ap.add_argument("--ontology", required=True, help="Path to the .ttl ontology")
    ap.add_argument("--out", default="", help="Output dir for generated code")
    ap.add_argument(
        "--render-ttl",
        action="store_true",
        help="Print the ontology re-rendered from the IR (round-trip) and exit",
    )
    args = ap.parse_args()

    from orchestrata_ultimate.domaingen import (
        generate_code,
        parse_ontology,
        render_ontology,
    )

    model = parse_ontology(Path(args.ontology))
    print(
        f"parsed: {len(model.all_entities())} entities in module(s) "
        f"{[m.name for m in model.modules]} (namespace {model.namespace})",
        file=sys.stderr,
    )

    if args.render_ttl:
        print(render_ontology(model))
        return 0

    if not args.out:
        ap.error("--out is required unless --render-ttl is given")
    paths = generate_code(model, args.out)
    for path in paths:
        print(path)
    return 0


if __name__ == "__main__":
    sys.exit(main())