4
0
mirror of https://github.com/nerfstudio-project/nerfstudio.git synced 2026-11-11 18:44:21 +08:00
nerfstudio/scripts/viewer/sync_viser_message_defs.py
Brent Yi c1c7a3b283
Fix ns-install-cli (#1754)
* Make ns-dev-sync-viser-message-defs a tyro CLI to fix ns-install-cli error

* Fix pylint
2023-04-17 17:57:04 -07:00

43 lines
1.3 KiB
Python

"""Generate viser message definitions for TypeScript, by parsing Python dataclasses."""
import pathlib
import subprocess
import tyro
from viser.infra import generate_typescript_interfaces
from nerfstudio.viewer.viser import NerfstudioMessage
def main() -> None:
"""Generate viser message definitions for TypeScript, by parsing Python dataclasses."""
# Generate typescript source.
defs = generate_typescript_interfaces(NerfstudioMessage)
# Write to file.
# Three parents from nerfstudio/scripts/viewer/sync_viser_message_defs.py:
# - nerfstudio/scripts/viewer/
# - nerfstudio/scripts/
# - nerfstudio/
target_path = pathlib.Path(__file__).absolute().parent.parent.parent / pathlib.Path(
"nerfstudio/viewer/app/src/modules/WebSocket/ViserMessages.tsx"
)
assert target_path.exists()
target_path.write_text(defs, encoding="utf_8")
print(f"Wrote to {target_path}")
# Run prettier.
# TODO: if this is not installed maybe we should print some error with installation
# instructions?
subprocess.run(args=["prettier", "-w", str(target_path)], check=False)
def entrypoint() -> None:
"""Entrypoint for use with pyproject scripts."""
# All entrypoints must currently be tyro CLIs.
tyro.cli(main)
if __name__ == "__main__":
entrypoint()