File size: 3,445 Bytes
3f4bb1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause

"""Update the comprehensive environment list in ``environments.rst``.

Maintainer tooling: reads the Gym registry (RL libraries, presets, workflows,
and inference task names) and rewrites the auto-generated section in
``docs/source/overview/environments.rst``.

Example usage::

    python tools/update_environments_rst.py
    python tools/update_environments_rst.py --check
"""

from __future__ import annotations

import argparse
import contextlib
import sys
from pathlib import Path


def _bootstrap_paths() -> None:
    """Prepend editable ``source/*`` packages and ``tools/`` for dev-tree runs."""
    repo_root = Path(__file__).resolve().parents[1]
    source_dir = repo_root / "source"
    tools_dir = repo_root / "tools"

    prepend: list[str] = [str(tools_dir)]
    if source_dir.is_dir():
        for package_dir in sorted(source_dir.iterdir()):
            if not package_dir.is_dir():
                continue
            module_root = package_dir / package_dir.name
            if module_root.is_dir():
                prepend.append(str(package_dir))

    for path in reversed(prepend):
        if path not in sys.path:
            sys.path.insert(0, path)


_bootstrap_paths()

from environ_docs import (  # noqa: E402
    collect_environment_doc_rows,
    patch_environments_rst,
    render_comprehensive_list_table,
)

import isaaclab_tasks  # noqa: E402, F401

# PLACEHOLDER: Extension template (do not remove this comment)
with contextlib.suppress(ImportError):
    import isaaclab_tasks_experimental  # noqa: E402, F401


def _default_rst_path() -> Path:
    return Path(__file__).resolve().parents[1] / "docs" / "source" / "overview" / "environments.rst"


def main() -> int:
    """Generate and optionally write the comprehensive environment list."""
    parser = argparse.ArgumentParser(description="Update environments.rst from the Gym registry.")
    parser.add_argument(
        "--output",
        type=Path,
        default=_default_rst_path(),
        help="Path to environments.rst (default: docs/source/overview/environments.rst).",
    )
    parser.add_argument(
        "--check",
        action="store_true",
        help="Exit with code 1 when environments.rst is out of date instead of rewriting it.",
    )
    args = parser.parse_args()

    rows = collect_environment_doc_rows()
    generated_table = render_comprehensive_list_table(rows)

    output_path = args.output.resolve()
    original = output_path.read_text(encoding="utf-8")
    updated = patch_environments_rst(original, generated_table)

    if args.check:
        if updated != original:
            print(
                f"[ERROR] {output_path} is out of date. Run python tools/update_environments_rst.py to refresh it.",
                file=sys.stderr,
            )
            return 1
        print(f"[INFO] {output_path} is up to date ({len(rows)} training environments).")
        return 0

    if updated == original:
        print(f"[INFO] {output_path} already up to date ({len(rows)} training environments).")
        return 0

    output_path.write_text(updated, encoding="utf-8")
    print(f"[INFO] Updated {output_path} with {len(rows)} training environments.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())