Skip to content

Commit

Permalink
added documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
BolunDai0216 committed Aug 6, 2024
1 parent f64c20e commit 70e8ee5
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 2 deletions.
Binary file added .DS_Store
Binary file not shown.
44 changes: 44 additions & 0 deletions .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Deploy Docs
on:
push:
branches: [master]

permissions:
contents: write

jobs:
docs:
name: Generate Website
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install docs dependencies
run: pip install -r docs/requirements.txt

- name: Install MPE2
run: pip install -e .

- name: Run some auxiliary scripts, e.g. build environments docs
run: python docs/_scripts/gen_envs_mds.py

- name: Build
run: sphinx-build -b dirhtml -v docs _build

- name: Move 404
run: mv _build/404/index.html _build/404.html

- name: Update 404 links
run: python docs/_scripts/move_404.py _build/404.html

- name: Remove .doctrees
run: rm -r _build/.doctrees

- name: Upload to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: _build
4 changes: 2 additions & 2 deletions .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
# Big Sur, Monterey
os: [macos-11, macos-12]
# Monterey
os: [macos-12]
python-version: ['3.8', '3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v4
Expand Down
7 changes: 7 additions & 0 deletions docs/404.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
hide-toc: true
---

# 404 - Page Not Found

## The requested page could not be found.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# MPE2 documentation

This directory contains the documentation for MPE2.

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)
62 changes: 62 additions & 0 deletions docs/_scripts/ipynb_to_gallery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Convert jupyter notebook to sphinx gallery notebook styled examples.
Usage: python ipynb_to_gallery.py <notebook.ipynb>
Dependencies: pypandoc, beautifulsoup4, numpy
install using `pip install pypandoc, beautifulsoup4, numpy`
"""
import json
import warnings

import numpy as np
import pypandoc as pdoc
from bs4 import BeautifulSoup

warnings.filterwarnings(
"ignore",
message="The input looks more like a filename than markup. You may want to open this file and pass the filehandle into Beautiful Soup",
)


def convert_ipynb_to_gallery(file_name):
python_file = ""

nb_dict = json.load(open(file_name))
cells = nb_dict["cells"]

for i, cell in enumerate(cells):
if i == 0:
assert cell["cell_type"] == "markdown", "First cell has to be markdown"

md_source = "".join(cell["source"])
rst_source = pdoc.convert_text(md_source, "rst", "md")
python_file = '"""\n' + rst_source + '\n"""'
else:
if cell["cell_type"] == "markdown":
md_source = "".join(cell["source"])
is_all_lines_html = np.all(
[
bool(BeautifulSoup(line, "html.parser").find())
for line in cell["source"]
]
)
if is_all_lines_html:
rst_source = pdoc.convert_text(
source=md_source, to="rst", format="html"
)
else:
rst_source = pdoc.convert_text(md_source, "rst", "md")
commented_source = "\n".join(["# " + x for x in rst_source.split("\n")])
python_file = python_file + "\n\n\n" + "# %%" + "\n" + commented_source
elif cell["cell_type"] == "code":
source = "".join(cell["source"])
python_file = python_file + "\n" * 2 + source

python_file = python_file.replace("\n%", "\n# %")
open(file_name.replace(".ipynb", ".py"), "w").write(python_file)


if __name__ == "__main__":
import sys

convert_ipynb_to_gallery(sys.argv[-1])
14 changes: 14 additions & 0 deletions docs/_scripts/move_404.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import sys

if __name__ == "__main__":
if len(sys.argv) < 2:
print("Provide a path")
filePath = sys.argv[1]

with open(filePath, "r+") as fp:
content = fp.read()
content = content.replace('href="../', 'href="/').replace('src="../', 'src="/')
fp.seek(0)
fp.truncate()

fp.write(content)
Binary file added docs/_static/img/MPE2-github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions docs/_static/img/MPE2_black.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions docs/_static/img/MPE2_white.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/img/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------
import os
from typing import Any, Dict
import mpe2


project = "MPE2"
copyright = "2024 Farama Foundation"
author = "Farama Foundation"

# The full version, including alpha/beta/rc tags
release = mpe2.__version__


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.napoleon",
"sphinx.ext.doctest",
"sphinx.ext.autodoc",
"sphinx.ext.githubpages",
"myst_parser",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# Napoleon settings
# napoleon_use_ivar = True
napoleon_use_admonition_for_references = True
# See https://github.com/sphinx-doc/sphinx/issues/9119
napoleon_custom_sections = [("Returns", "params_style")]

# Autodoc
autoclass_content = "both"
autodoc_preserve_defaults = True

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "furo"
html_title = "MPE2 Documentation"
html_baseurl = "https://mpe2.farama.org"
html_copy_source = False
html_favicon = "_static/img/favicon.png"
html_theme_options = {
"light_logo": "img/mpe2_black.svg",
"dark_logo": "img/mpe2_white.svg",
"gtag": "G-6H9C8TWXZ8",
"description": "mpe2 DESCRIPTION",
"image": "img/mpe2-github.png",
"versioning": True,
"source_repository": "https://github.com/Farama-Foundation/MPE2/",
"source_branch": "main",
"source_directory": "docs/",
}

html_static_path = ["_static"]
html_css_files = []

# -- Generate Changelog -------------------------------------------------

sphinx_github_changelog_token = os.environ.get("SPHINX_GITHUB_CHANGELOG_TOKEN")
14 changes: 14 additions & 0 deletions docs/content/basic_usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
layout: "contents"
title: Basic Usage
firstpage:
---

# Basic Usage

## Installation

```
pip install mpe2
```

52 changes: 52 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
hide-toc: true
firstpage:
lastpage:
---

```{project-logo} _static/MPE2-text.png
:alt: MPE2 Logo
```

```{project-heading}
Description of the Project
```

**Basic example:**

```{code-block} python
from mpe2 import simple_push_v3
env = simple_push_v3.env(render_mode="human")
env.reset(seed=42)
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
if termination or truncation:
action = None
else:
# this is where you would insert your policy
action = env.action_space(agent).sample()
env.step(action)
env.close()
```

```{toctree}
:hidden:
:caption: Introduction
content/basic_usage
```

```{toctree}
:hidden:
:caption: Development
Github <https://github.com/Farama-Foundation/MPE2>
release_notes/index
Contribute to the Docs <https://github.com/Farama-Foundation/MPE2/blob/main/docs/README.md>
```
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
5 changes: 5 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sphinx
sphinx-autobuild
myst-parser
git+https://github.com/Farama-Foundation/Celshast#egg=furo
sphinx_github_changelog
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ testing = [
"pytest-markdown-docs==0.5.0",
]

documentation = [
"furo@git+https://github.com/Farama-Foundation/Celshast.git",
"sphinx-autobuild==2024.4.16",
"myst-parser==4.0.0",
]

# Linters and Test tools #######################################################

[tool.black]
Expand Down

0 comments on commit 70e8ee5

Please sign in to comment.