Build the web-studio SPA and copy dist into the Python package tree. Skipped when OV_SKIP_STUDIO_BUILD=1 or when the bundle already exists. Falls back gracefully (warning, not error) when npm is unavailable.
()
| 461 | |
| 462 | |
| 463 | def _build_web_studio(): |
| 464 | """Build the web-studio SPA and copy dist into the Python package tree. |
| 465 | |
| 466 | Skipped when OV_SKIP_STUDIO_BUILD=1 or when the bundle already exists. |
| 467 | Falls back gracefully (warning, not error) when npm is unavailable. |
| 468 | """ |
| 469 | if os.environ.get("OV_SKIP_STUDIO_BUILD") == "1": |
| 470 | print(" [SKIP] web-studio build disabled by OV_SKIP_STUDIO_BUILD=1") |
| 471 | return |
| 472 | |
| 473 | dest = SETUP_DIR / "openviking" / "web_studio" / "dist" |
| 474 | if (dest / "index.html").is_file(): |
| 475 | print(" [OK] web-studio bundle already present") |
| 476 | return |
| 477 | |
| 478 | source = SETUP_DIR / "web-studio" |
| 479 | if not (source / "package.json").is_file(): |
| 480 | print(" [SKIP] web-studio source not found; /studio will be unavailable") |
| 481 | return |
| 482 | |
| 483 | npm = shutil.which("npm") |
| 484 | if not npm: |
| 485 | print(" [SKIP] npm not found; install Node.js to enable /studio") |
| 486 | return |
| 487 | |
| 488 | print("Building web-studio (Vite SPA)...") |
| 489 | try: |
| 490 | subprocess.check_call([npm, "ci"], cwd=str(source)) |
| 491 | subprocess.check_call( |
| 492 | [npm, "run", "build", "--", "--base=/studio/"], |
| 493 | cwd=str(source), |
| 494 | ) |
| 495 | except subprocess.CalledProcessError as exc: |
| 496 | print(f" [WARNING] web-studio npm build failed ({exc}); /studio will be unavailable") |
| 497 | return |
| 498 | |
| 499 | built = source / "dist" |
| 500 | if not (built / "index.html").is_file(): |
| 501 | print(" [WARNING] web-studio build produced no index.html; /studio will be unavailable") |
| 502 | return |
| 503 | |
| 504 | dest.parent.mkdir(parents=True, exist_ok=True) |
| 505 | if dest.exists(): |
| 506 | shutil.rmtree(dest) |
| 507 | shutil.copytree(built, dest) |
| 508 | print(f" [OK] web-studio bundle copied to {dest}") |
| 509 | |
| 510 | |
| 511 | class OpenVikingBuildPy(build_py): |