mjlab/typings/generate_mujoco_stubs.sh
Upstream Snapshot 32a241c28f
Some checks failed
nightly / Test against latest dependencies (py3.10) (push) Has been cancelled
nightly / Test against latest dependencies (py3.13) (push) Has been cancelled
tests / tests (3.13, locked) (push) Has been cancelled
tests / tests (3.13, unlocked) (push) Has been cancelled
tests / pyright (3.10) (push) Has been cancelled
tests / lint-format (push) Has been cancelled
tests / tests (3.10, locked) (push) Has been cancelled
tests / tests (3.11, locked) (push) Has been cancelled
tests / tests (3.12, locked) (push) Has been cancelled
tests / pyright (3.11) (push) Has been cancelled
tests / pyright (3.12) (push) Has been cancelled
tests / pyright (3.13) (push) Has been cancelled
tests / ty-check (3.10) (push) Has been cancelled
tests / ty-check (3.11) (push) Has been cancelled
tests / ty-check (3.12) (push) Has been cancelled
tests / ty-check (3.13) (push) Has been cancelled
tests / stubs (push) Has been cancelled
tests / smoke-test (push) Has been cancelled
Docker / check_paths (push) Has been cancelled
docs / build (push) Has been cancelled
Docker / build (push) Has been cancelled
Import upstream snapshot c19f713c415a699a79d71cd96aa13c3104a05047
Upstream: https://github.com/michaelgillett/mjlab
Upstream-Commit: c19f713c415a699a79d71cd96aa13c3104a05047
Upstream-Branch: main
2026-08-28 15:42:17 +08:00

35 lines
1.5 KiB
Bash

#!/usr/bin/env bash
# Generate type stubs for MuJoCo using pybind11-stubgen.
# This helps suppress pyright/ty errors for MuJoCo's C++ bindings.
#
# The output is post-processed by postprocess_stubs.py to make it
# platform-independent (it drops the OpenGL backend stubs, which differ between
# macOS and Linux). This keeps the committed stubs identical on every platform,
# so CI can regenerate them and fail if they drift from the installed mujoco
# version. pybind11-stubgen is pinned so its output is reproducible.
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# --no-sync runs in the already-synced project environment (so mujoco is
# importable) without disturbing it; the conflicting cpu/cu128 extras mean a
# plain "uv run" would re-sync and churn the environment.
STUBGEN_VERSION="2.5.5"
STUBGEN=(uv run --no-sync --with "pybind11-stubgen==${STUBGEN_VERSION}" pybind11-stubgen)
echo "Generating MuJoCo type stubs..."
"${STUBGEN[@]}" mujoco -o "$SCRIPT_DIR" --ignore-all-errors
# mujoco.viewer pulls in GLFW, which may not import on a headless machine.
# Skip it in that case rather than failing; the committed viewer stub is kept.
if ! "${STUBGEN[@]}" mujoco.viewer -o "$SCRIPT_DIR" --ignore-all-errors; then
echo "Warning: could not generate mujoco.viewer stubs (no GLFW?). Skipping."
fi
echo "Post-processing stubs to make them platform-independent..."
uv run --no-sync python "$SCRIPT_DIR/postprocess_stubs.py"
echo "MuJoCo stubs generated successfully in $SCRIPT_DIR/mujoco/"