53def model_path(name: str, *, env_var: str |
None =
None) -> str:
54 """Return a filesystem path to the named Menagerie model.
56 If ``env_var`` is set, that value is used as a user override; it must
57 point at an existing file or a RuntimeError is raised. Otherwise the
58 fetched cache is used; if it is missing, a RuntimeError explains how to
62 override = os.environ.get(env_var)
64 if not Path(override).exists():
65 raise RuntimeError(f
"{env_var}={override} was set but does not exist")
69 subdir, filename = _MODELS[name]
71 raise KeyError(f
"unknown Menagerie model '{name}'; known: {sorted(_MODELS)}")
from None
73 env = os.environ.get(
"MJ_KDL_MENAGERIE")
76 candidate = root / subdir / filename
77 if candidate.exists():
80 searched =
", ".join(str(root / subdir / filename)
for root
in roots)
82 f
"Menagerie model '{name}' was not found. Searched: {searched}. Fetch the models "
83 f
"with the 'mj-kdl-fetch-menagerie' console script, set MJ_KDL_MENAGERIE to a "
84 f
"MuJoCo Menagerie checkout, or set {env_var or 'the model env var'} to a model file."
124def fetch(dest: str | os.PathLike[str] |
None =
None) -> dict[str, str]:
125 """Shallow-clone the full MuJoCo Menagerie into ``dest`` (default: cache).
127 Returns a mapping of model name -> resolved path. Requires ``git``.
129 if shutil.which(
"git")
is None:
130 raise RuntimeError(
"git is required to fetch MuJoCo Menagerie")
132 target = Path(dest)
if dest
is not None else _cache_dir()
133 if not (target /
".git").exists():
134 target.parent.mkdir(parents=
True, exist_ok=
True)
135 shutil.rmtree(target, ignore_errors=
True)
136 if not _run([
"git",
"clone",
"--depth",
"1", MENAGERIE_REPO, str(target)]):
137 raise RuntimeError(f
"failed to clone {MENAGERIE_REPO}")
140 for name, (subdir, filename)
in _MODELS.items():
141 path = target / subdir / filename
142 if not path.exists():
143 raise RuntimeError(f
"expected {path} after fetch, but it is missing")
144 resolved[name] = str(path)
150 """Copy bundled mj_kdl_wrapper assets into ``dest`` (default: cache)."""
152 target.parent.mkdir(parents=
True, exist_ok=
True)
154 with resources.as_file(resources.files(
"mj_kdl_wrapper") /
"assets")
as assets_src:
155 if assets_src.exists():
156 shutil.copytree(assets_src, target, dirs_exist_ok=
True)
163 raise RuntimeError(
"bundled mj_kdl_wrapper assets are missing")