|
| 1 | +"""Unified ``wuji`` command-line entry for the deploy + real2sim toolchain. |
| 2 | +
|
| 3 | +Installed as a console script by the ``examples/wuji[deploy]`` extra, so the |
| 4 | +whole pipeline runs through one verb instead of long ``python -m`` module paths:: |
| 5 | +
|
| 6 | + uv run wuji <command> [options] |
| 7 | + uv run wuji play --ckpt policy.onnx --real --goal-mode random |
| 8 | + uv run wuji <command> --help # per-command options |
| 9 | +
|
| 10 | +Each command lazily imports its target module so that, e.g., ``wuji play`` does |
| 11 | +not pull in the Hikvision MVS SDK that ``wuji observer`` needs (and vice-versa) — |
| 12 | +the observer module raises at import time when the SDK is absent. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import importlib |
| 18 | +import sys |
| 19 | + |
| 20 | +# command -> (module, prefix-args prepended before user args) |
| 21 | +# prefix-args let two verbs share one module (hand_utils' check / home subparser). |
| 22 | +_COMMANDS: dict[str, tuple[str, tuple[str, ...]]] = { |
| 23 | + "check": ("genelab_wuji.deploy.scripts.hand_utils", ("check",)), |
| 24 | + "home": ("genelab_wuji.deploy.scripts.hand_utils", ("home",)), |
| 25 | + "observer": ("genelab_wuji.deploy.scripts.cube_world_observer", ()), |
| 26 | + "viewer": ("genelab_wuji.deploy.scripts.toreal_viewer", ()), |
| 27 | + "calib": ("genelab_wuji.deploy.scripts.calib_check", ()), |
| 28 | + "play": ("genelab_wuji.deploy.scripts.play_real", ()), |
| 29 | +} |
| 30 | + |
| 31 | +_HELP: dict[str, str] = { |
| 32 | + "check": "read-only hand-bridge test (connection + encoder sanity)", |
| 33 | + "home": "ease-in-out ramp the hand to the grasp pose", |
| 34 | + "observer": "Hikvision camera -> ArUco cube pose, published on ZMQ", |
| 35 | + "viewer": "real2sim Genesis mirror of the observed cube", |
| 36 | + "calib": "calibration viewer: live hand + observed cube vs. digital twin", |
| 37 | + "play": "deploy control loop (real/mock) + goal modes + success monitor", |
| 38 | +} |
| 39 | + |
| 40 | + |
| 41 | +def _usage() -> str: |
| 42 | + width = max(len(c) for c in _COMMANDS) |
| 43 | + lines = ["usage: wuji <command> [options]", "", "commands:"] |
| 44 | + lines += [f" {name:<{width}} {_HELP[name]}" for name in _COMMANDS] |
| 45 | + lines += ["", "run `wuji <command> --help` for per-command options."] |
| 46 | + return "\n".join(lines) |
| 47 | + |
| 48 | + |
| 49 | +def main(argv: list[str] | None = None) -> int: |
| 50 | + argv = list(sys.argv[1:] if argv is None else argv) |
| 51 | + if not argv: |
| 52 | + print(_usage(), file=sys.stderr) |
| 53 | + return 2 |
| 54 | + cmd, rest = argv[0], argv[1:] |
| 55 | + if cmd in ("-h", "--help", "help"): |
| 56 | + print(_usage()) |
| 57 | + return 0 |
| 58 | + if cmd not in _COMMANDS: |
| 59 | + print(f"wuji: unknown command {cmd!r}\n", file=sys.stderr) |
| 60 | + print(_usage(), file=sys.stderr) |
| 61 | + return 2 |
| 62 | + module_name, prefix = _COMMANDS[cmd] |
| 63 | + module = importlib.import_module(module_name) |
| 64 | + return int(module.main([*prefix, *rest]) or 0) |
| 65 | + |
| 66 | + |
| 67 | +if __name__ == "__main__": |
| 68 | + raise SystemExit(main()) |
0 commit comments