Source code for simvx.graphics.cli

"""``simvx build-textures`` subcommand: registered via the ``simvx.commands``
entry point (the sanctioned no-upward-import mechanism: core discovers it, never
imports graphics).

Compiles the native basis_universal UASTC->BC7 transcoder extension. Required
once after ``uv pip install -e packages/graphics`` because uv_build does not run
C-extension build hooks, mirroring core's ``simvx build-audio``. Subsequent runs
reuse the .so.
"""

import argparse
import sys


def _cmd_build_textures(args: argparse.Namespace) -> int:
    try:
        from ._native.basis_transcoder_build import build
    except ImportError as exc:
        print(f"Failed to import build script: {exc}", file=sys.stderr)
        return 1
    try:
        built = build()
    except Exception as exc:  # noqa: BLE001
        print(f"Build failed: {exc}", file=sys.stderr)
        return 1
    print(f"Built native texture transcoder: {built}")
    return 0


[docs] def register(subparsers: argparse._SubParsersAction) -> None: """Attach ``build-textures`` to the ``simvx`` CLI.""" p = subparsers.add_parser( "build-textures", help="Compile the native basis_universal UASTC->BC7 transcoder (one-time, per install).", ) p.set_defaults(func=_cmd_build_textures)