Skip to content

Commit

Permalink
fix env table gen
Browse files Browse the repository at this point in the history
  • Loading branch information
younik committed Nov 2, 2024
1 parent 81d803b commit 28e7945
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Build Documentation website
on:
pull_request:
push:
branches: [main]
permissions:
Expand Down
30 changes: 25 additions & 5 deletions docs/_scripts/gen_dataset_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
from multiprocessing import Pool
from typing import OrderedDict

import generate_env_table
import generate_gif
from gymnasium.envs.registration import EnvSpec
from md_utils import dict_to_table

import minari
from minari.dataset.minari_dataset import gen_dataset_id, parse_dataset_id
from minari.namespace import download_namespace_metadata, get_namespace_metadata
from minari.utils import get_dataset_spec_dict, get_env_spec_dict
from minari.utils import get_dataset_spec_dict


DATASET_FOLDER = pathlib.Path(__file__).parent.parent.joinpath("datasets")
Expand Down Expand Up @@ -181,7 +181,18 @@ def _generate_dataset_page(arg):
else:
env_docs += PRE_TRAIN_ENV_MSG.format(dataset_id)
env_docs += "\n"
env_docs += dict_to_table(get_env_spec_dict(EnvSpec.from_json(env_spec)))

train_spec_file = f"train_spec_{dataset_id}.md"
subprocess.check_call(
[
python_path,
generate_env_table.__file__,
f"--env_spec={env_spec}",
f"--file_name={train_spec_file}",
]
)

env_docs += pathlib.Path(train_spec_file).read_text()
env_docs += "\n"

env_docs += """\n## Evaluation Environment Specs\n"""
Expand All @@ -190,9 +201,18 @@ def _generate_dataset_page(arg):
else:
env_docs += PRE_EVAL_ENV_MSG.format(dataset_id)
env_docs += "\n"
env_docs += dict_to_table(
get_env_spec_dict(EnvSpec.from_json(eval_env_spec))

eval_spec_file = f"eval_spec_{dataset_id}.md"
subprocess.check_call(
[
python_path,
generate_env_table.__file__,
f"--env_spec={env_spec}",
f"--file_name={eval_spec_file}",
]
)

env_docs += pathlib.Path(eval_spec_file).read_text()
env_docs += "\n"

content = "---\nautogenerated:\n"
Expand Down
23 changes: 23 additions & 0 deletions docs/_scripts/generate_env_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

from absl import app, flags

from gymnasium.envs.registration import EnvSpec

from minari.utils import get_env_spec_dict
from md_utils import dict_to_table

FLAGS = flags.FLAGS
flags.DEFINE_string("env_spec", None, "Environment spec json file")
flags.DEFINE_string("file_name", None, "File name to save the md file")


def main(argv):
del argv
env_spec_dict = get_env_spec_dict(EnvSpec.from_json(FLAGS.env_spec))
md_table = dict_to_table(env_spec_dict)
with open(FLAGS.file_name, "w") as f:
f.write(md_table)


if __name__ == "__main__":
app.run(main)

0 comments on commit 28e7945

Please sign in to comment.