Spaces:
Running
Running
File size: 7,142 Bytes
b4ac377 | 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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | # Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
import os
import sys
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = "OpenEnv"
copyright = ""
author = ""
# -- Version configuration ---------------------------------------------------
# RELEASE env var controls stable vs dev builds (set by `make html-stable`)
RELEASE = os.environ.get("RELEASE", False)
# Read version from pyproject.toml
import tomli
pyproject_path = os.path.join(os.path.dirname(__file__), "..", "..", "pyproject.toml")
with open(pyproject_path, "rb") as f:
pyproject_data = tomli.load(f)
openenv_version = pyproject_data["project"]["version"]
if RELEASE:
version = ".".join(openenv_version.split(".")[:2])
release = version
html_title = f"OpenEnv {version} documentation"
switcher_version = version
else:
version = "main"
release = "main"
html_title = "OpenEnv"
switcher_version = "main"
# -- Path setup --------------------------------------------------------------
sys.path.insert(0, os.path.abspath("../../src"))
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
"sphinx_design",
"sphinx_sitemap",
"sphinxcontrib.mermaid",
"pytorch_sphinx_theme2",
"sphinxext.opengraph",
"myst_parser",
"sphinx.ext.autodoc",
"sphinx.ext.autosummary",
"sphinx_gallery.gen_gallery",
]
# -- sphinx-gallery configuration --------------------------------------------
from sphinx_gallery.sorting import FileNameSortKey
sphinx_gallery_conf = {
"examples_dirs": ["getting_started"],
"gallery_dirs": ["auto_getting_started"],
"filename_pattern": r"/plot_",
"ignore_pattern": r"__init__\.py",
"download_all_examples": False,
"show_memory": False,
"capture_repr": ("_repr_html_", "__repr__"),
"matplotlib_animations": True,
"remove_config_comments": True,
"within_subsection_order": FileNameSortKey,
"default_thumb_file": None,
"nested_sections": False,
}
exclude_patterns = ["getting_started/*.md", "getting_started/README.rst"]
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
import pytorch_sphinx_theme2
html_theme = "pytorch_sphinx_theme2"
html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()]
html_static_path = ["_static"]
html_theme_options = {
"navigation_with_keys": False,
"analytics_id": "GTM-NPLPKN5G",
"header_links_before_dropdown": 7,
"logo": {
"text": "OpenEnv",
},
"icon_links": [
{
"name": "X",
"url": "https://x.com/PyTorch",
"icon": "fa-brands fa-x-twitter",
},
{
"name": "GitHub",
"url": "https://github.com/meta-pytorch/OpenEnv",
"icon": "fa-brands fa-github",
},
{
"name": "Discourse",
"url": "https://dev-discuss.pytorch.org/",
"icon": "fa-brands fa-discourse",
},
],
"use_edit_page_button": True,
"navbar_center": "navbar-nav",
"switcher": {
"json_url": "_static/versions.json",
"version_match": switcher_version,
},
"check_switcher": False,
"navbar_align": "left",
"navbar_start": ["navbar-logo", "version-switcher"],
"navbar_center": ["navbar-nav"],
"navbar_end": ["theme-switcher", "navbar-icon-links"],
}
theme_variables = pytorch_sphinx_theme2.get_theme_variables()
# Templates path - local templates override theme templates
templates_path = [
"_templates",
os.path.join(os.path.dirname(pytorch_sphinx_theme2.__file__), "templates"),
]
html_context = {
"theme_variables": theme_variables,
"display_github": True,
"github_url": "https://github.com",
"github_user": "meta-pytorch",
"github_repo": "OpenEnv",
"feedback_url": "https://github.com/meta-pytorch/OpenEnv",
"github_version": "main",
"doc_path": "docs/source",
"library_links": theme_variables.get("library_links", []),
"community_links": theme_variables.get("community_links", []),
"language_bindings_links": html_theme_options.get("language_bindings_links", []),
}
# Base URL for the site (used by sitemap and canonical URLs)
html_baseurl = "https://meta-pytorch.org/OpenEnv/"
sitemap_locales = [None]
sitemap_excludes = [
"search.html",
"genindex.html",
]
sitemap_url_scheme = "{link}"
# -- MyST-Parser configuration -----------------------------------------------
myst_enable_extensions = [
"colon_fence",
"deflist",
"html_image",
]
# -- Post-process sphinx-gallery output to fix navigation --------------------
def remove_orphan_and_duplicate_toctree(app, docname, source):
"""Remove :orphan: and duplicate hidden toctree from gallery index."""
if docname == "auto_getting_started/index":
content = source[0]
# Remove the :orphan: directive
if content.startswith(":orphan:"):
content = content.replace(":orphan:\n\n", "", 1)
content = content.replace(":orphan:\n", "", 1)
# Remove the sphinx-gallery generated hidden toctree
# Find and remove the hidden toctree block
import re
# Match: .. toctree::\n :hidden:\n\n /auto_getting_started/...
pattern = r"\.\. toctree::\n\s+:hidden:\n\n(?:\s+/auto_getting_started/plot_\d+_\w+\n)+"
content = re.sub(pattern, "", content)
source[0] = content
def copy_md_pages_to_gallery(app):
"""Copy .md pages from getting_started/ to auto_getting_started/.
Sphinx Gallery only processes .py files and README.rst. Any extra .md
pages that live alongside the gallery source must be copied into the
generated gallery directory so Sphinx can discover them as part of the
same toctree (important for section-nav context in pydata-sphinx-theme).
"""
import glob
import shutil
srcdir = os.path.join(app.srcdir, "getting_started")
dstdir = os.path.join(app.srcdir, "auto_getting_started")
os.makedirs(dstdir, exist_ok=True)
for md_file in glob.glob(os.path.join(srcdir, "*.md")):
shutil.copy2(md_file, dstdir)
def setup(app):
# Copy extra .md pages into the gallery output dir (priority 900 so it
# runs after sphinx-gallery's builder-inited handler at default priority).
app.connect("builder-inited", copy_md_pages_to_gallery, priority=900)
# Hook into source-read to modify content before Sphinx processes it
app.connect("source-read", remove_orphan_and_duplicate_toctree)
|