| |
| |
| |
| |
|
|
| import os |
| import sys |
|
|
| |
| |
|
|
| project = "OpenEnv" |
| copyright = "" |
| author = "" |
|
|
| |
| |
| RELEASE = os.environ.get("RELEASE", False) |
|
|
| |
| 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" |
|
|
| |
| sys.path.insert(0, os.path.abspath("../../src")) |
|
|
| |
| |
|
|
| extensions = [ |
| "sphinx_design", |
| "sphinx_sitemap", |
| "sphinxcontrib.mermaid", |
| "pytorch_sphinx_theme2", |
| "sphinxext.opengraph", |
| "myst_parser", |
| "sphinx.ext.autodoc", |
| "sphinx.ext.autosummary", |
| "sphinx_gallery.gen_gallery", |
| ] |
|
|
| |
| 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"] |
|
|
| |
| |
|
|
| 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 = [ |
| "_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", []), |
| } |
|
|
| |
| html_baseurl = "https://meta-pytorch.org/OpenEnv/" |
| sitemap_locales = [None] |
| sitemap_excludes = [ |
| "search.html", |
| "genindex.html", |
| ] |
| sitemap_url_scheme = "{link}" |
|
|
| |
| myst_enable_extensions = [ |
| "colon_fence", |
| "deflist", |
| "html_image", |
| ] |
|
|
|
|
| |
| 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] |
| |
| if content.startswith(":orphan:"): |
| content = content.replace(":orphan:\n\n", "", 1) |
| content = content.replace(":orphan:\n", "", 1) |
|
|
| |
| |
| import re |
|
|
| |
| 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): |
| |
| |
| app.connect("builder-inited", copy_md_pages_to_gallery, priority=900) |
| |
| app.connect("source-read", remove_orphan_and_duplicate_toctree) |
|
|