Переглянути джерело

Pull env attributes to docs (#362)

Manuel Goulão 1 рік тому
батько
коміт
ceb80ec1fd

+ 3 - 3
.github/workflows/build-docs-dev.yml

@@ -24,10 +24,10 @@ jobs:
         run: pip install -e .
 
       - name: Build Envs Docs
-        run: python docs/scripts/gen_mds.py
+        run: python docs/_scripts/gen_env_docs.py
 
       - name: Build Envs Display
-        run: python docs/scripts/gen_envs_display.py
+        run: python docs/_scripts/gen_envs_display.py
 
       - name: Build
         run: sphinx-build -b dirhtml -v docs _build
@@ -36,7 +36,7 @@ jobs:
         run: mv _build/404/index.html _build/404.html
 
       - name: Update 404 links
-        run: python docs/scripts/move_404.py _build/404.html
+        run: python docs/_scripts/move_404.py _build/404.html
 
       - name: Remove .doctrees
         run: rm -r _build/.doctrees

+ 3 - 3
.github/workflows/build-docs-version.yml

@@ -29,10 +29,10 @@ jobs:
         run: pip install -e .
 
       - name: Build Envs Docs
-        run: python docs/scripts/gen_mds.py
+        run: python docs/_scripts/gen_env_docs.py
 
       - name: Build Envs Display
-        run: python docs/scripts/gen_envs_display.py
+        run: python docs/_scripts/gen_envs_display.py
 
       - name: Build
         run: sphinx-build -b dirhtml -v docs _build
@@ -41,7 +41,7 @@ jobs:
         run: mv _build/404/index.html _build/404.html
 
       - name: Update 404 links
-        run: python docs/scripts/move_404.py _build/404.html
+        run: python docs/_scripts/move_404.py _build/404.html
 
       - name: Remove .doctrees
         run: rm -r _build/.doctrees

+ 3 - 3
.github/workflows/manual-build-docs-version.yml

@@ -40,10 +40,10 @@ jobs:
         run: pip install -e .
 
       - name: Build Envs Docs
-        run: python docs/scripts/gen_mds.py
+        run: python docs/_scripts/gen_env_docs.py
 
       - name: Build Envs Display
-        run: python docs/scripts/gen_envs_display.py
+        run: python docs/_scripts/gen_envs_display.py
 
       - name: Build
         run: sphinx-build -b dirhtml -v docs _build
@@ -52,7 +52,7 @@ jobs:
         run: mv _build/404/index.html _build/404.html
 
       - name: Update 404 links
-        run: python docs/scripts/move_404.py _build/404.html
+        run: python docs/_scripts/move_404.py _build/404.html
 
       - name: Remove .doctrees
         run: rm -r _build/.doctrees

+ 3 - 3
docs/README.md

@@ -1,15 +1,15 @@
 # MiniGrid documentation
 
 
-This folder contains the documentation for MiniGrid. 
+This folder contains the documentation for MiniGrid.
 
 For more information about how to contribute to the documentation go to our [CONTRIBUTING.md](https://github.com/Farama-Foundation/Celshast/blob/main/CONTRIBUTING.md)
 
 ### Editing an environment page
 
-If you are editing an Atari environment, directly edit the md file in this repository. 
+If you are editing an Atari environment, directly edit the Markdown file in this repository.
 
-Otherwise, fork Gym and edit the docstring in the environment's Python file. Then, pip install your Gym fork and run `docs/scripts/gen_mds.py` in this repo. This will automatically generate a md documentation file for the environment.
+Otherwise, fork Gym and edit the docstring in the environment's Python file. Then, pip install your Gym fork and run `docs/_scripts/gen_env_docs.py` in this repo. This will automatically generate a md documentation file for the environment.
 
 ## Build the Documentation
 

+ 22 - 15
docs/scripts/gen_mds.py

@@ -1,29 +1,19 @@
-__author__ = "Feng Gu"
-__email__ = "contact@fenggu.me"
-
-"""
-   isort:skip_file
-"""
+from __future__ import annotations
 
 import os
 import re
+from itertools import chain
 
 from gymnasium.envs.registration import registry
 from tqdm import tqdm
-from utils import trim
-from itertools import chain
 
-from utils import env_name_format
+from utils import env_name_format, trim
 
 readme_path = os.path.join(
     os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
     "README.md",
 )
 
-LAYOUT = "env"
-
-pattern = re.compile(r"(?<!^)(?=[A-Z])")
-
 all_envs = list(registry.values())
 
 filtered_envs_by_type = {}
@@ -67,9 +57,9 @@ filtered_babyai_envs = {
 }
 
 for env_name, env_spec in chain(filtered_envs.items(), filtered_babyai_envs.items()):
-    made = env_spec.make()
+    env = env_spec.make()
 
-    docstring = trim(made.unwrapped.__doc__)
+    docstring = trim(env.unwrapped.__doc__)
 
     # minigrid.envs:Env or minigrid.envs.babyai:Env
     split = env_spec.entry_point.split(".")
@@ -95,11 +85,13 @@ for env_name, env_spec in chain(filtered_envs.items(), filtered_babyai_envs.item
 
     formatted_env_name = env_name_format(env_name)
 
+    # Front matter
     front_matter = f"""---
 autogenerated:
 title: {formatted_env_name}
 ---
 """
+    # Title and gif
     title = f"# {formatted_env_name}"
     gif = (
         "```{figure} "
@@ -110,6 +102,19 @@ title: {formatted_env_name}
 """
     )
 
+    # Environment attributes
+    action_space_table = env.action_space.__repr__().replace("\n", "")
+    observation_space_table = env.observation_space.__repr__().replace("\n", "")
+    env_attributes = f"""
+|   |   |
+|---|---|
+| Action Space | `{re.sub(' +', ' ', action_space_table)}` |
+| Observation Space | `{re.sub(' +', ' ', observation_space_table)}` |
+| Reward Range | `{env.reward_range}` |
+| Creation | `gymnasium.make("{env_spec.id}")` |
+"""
+
+    # Create Markdown file content
     if docstring is None:
         docstring = "No information provided"
     all_text = f"""{front_matter}
@@ -118,6 +123,8 @@ title: {formatted_env_name}
 
 {gif}
 
+{env_attributes}
+
 {docstring}
 """
     file = open(v_path, "w+", encoding="utf-8")

docs/scripts/gen_envs_display.py → docs/_scripts/gen_envs_display.py


docs/scripts/gen_gifs.py → docs/_scripts/gen_gifs.py


docs/scripts/move_404.py → docs/_scripts/move_404.py


docs/scripts/utils.py → docs/_scripts/utils.py


BIN
docs/_static/img/minigrid-text.png


+ 1 - 1
docs/index.md

@@ -4,7 +4,7 @@ firstpage:
 lastpage:
 ---
 
-```{project-logo} _static/img/minigrid-text.svg
+```{project-logo} _static/img/minigrid-text.png
 :alt: Minigrid Logo
 ```