Unverified Commit 8e4ee125 authored by Tim Moon's avatar Tim Moon Committed by GitHub
Browse files

Support building documentation in Python 3.12 (#1274)



* Update dependencies for building documentation
Signed-off-by: default avatarTim Moon <tmoon@nvidia.com>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci



* Patch RTD theme 3.0.0 to include version selector in sidebar
Signed-off-by: default avatarTim Moon <tmoon@nvidia.com>

* Debug printing version in sidebar
Signed-off-by: default avatarTim Moon <tmoon@nvidia.com>

---------
Signed-off-by: default avatarTim Moon <tmoon@nvidia.com>
Co-authored-by: default avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: default avatarKirthi Shankar Sivamani <ksivamani@nvidia.com>
parent 7cef7566
...@@ -17,8 +17,8 @@ jobs: ...@@ -17,8 +17,8 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: 'Install dependencies' - name: 'Install dependencies'
run: | run: |
pip install sphinx==5.1.1 sphinx_rtd_theme==1.0.0 nbsphinx==0.8.10 IPython ipython_genutils==0.2.0 ipywidgets==8.0.2 astroid==2.15.7 pip install sphinx==8.1.3 sphinx_rtd_theme==3.0.1 nbsphinx==0.9.5 IPython ipython_genutils==0.2.0 ipywidgets==8.0.2 astroid==3.3.2
pip install breathe==4.34.0 sphinx-autoapi==2.0.1 pip install breathe==4.35.0 sphinx-autoapi==3.3.2
sudo apt-get install -y pandoc graphviz doxygen sudo apt-get install -y pandoc graphviz doxygen
export GIT_SHA=$(git show-ref --hash HEAD) export GIT_SHA=$(git show-ref --hash HEAD)
- name: 'Build docs' - name: 'Build docs'
......
...@@ -22,9 +22,7 @@ __pycache__ ...@@ -22,9 +22,7 @@ __pycache__
.hypothesis .hypothesis
.devcontainer.json .devcontainer.json
tests/cpp/build/ tests/cpp/build/
docs/_build
.ipynb_checkpoints .ipynb_checkpoints
docs/doxygen
*.log *.log
CMakeFiles/CMakeSystem.cmake CMakeFiles/CMakeSystem.cmake
sdist/ sdist/
......
_build
doxygen
sphinx_rtd_theme
\ No newline at end of file
...@@ -16,5 +16,10 @@ help: ...@@ -16,5 +16,10 @@ help:
# Catch-all target: route all unknown targets to Sphinx using the new # Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile %: Makefile sphinx_rtd_theme
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) PYTHONPATH=sphinx_rtd_theme:$(PYTHONPATH) $(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
# Patch Sphinx RTD theme 3.0.1 to add version selector in sidebar
sphinx_rtd_theme:
git clone --depth=1 -b 3.0.1 --single-branch https://github.com/readthedocs/sphinx_rtd_theme.git
bash -c "cd sphinx_rtd_theme; git apply ../version_select.patch"
...@@ -2,38 +2,30 @@ ...@@ -2,38 +2,30 @@
# #
# See LICENSE for license information. # See LICENSE for license information.
import datetime
import os import os
import sys import pathlib
import sphinx_rtd_theme
from sphinx.ext.autodoc.mock import mock
from sphinx.ext.autodoc import between, ClassDocumenter, AttributeDocumenter
from sphinx.util import inspect
from builtins import str
from enum import Enum
import re
import subprocess import subprocess
from pathlib import Path from builtins import str
from datetime import date
te_path = os.path.dirname(os.path.realpath(__file__))
with open(te_path + "/../build_tools/VERSION.txt", "r") as f: # Basic project info
te_version = f.readline().strip() project = "Transformer Engine"
author = "NVIDIA CORPORATION & AFFILIATES"
# Copyright statement
release_year = 2022 release_year = 2022
current_year = datetime.date.today().year
current_year = date.today().year
if current_year == release_year: if current_year == release_year:
copyright_year = release_year copyright_year = release_year
else: else:
copyright_year = str(release_year) + "-" + str(current_year) copyright_year = str(release_year) + "-" + str(current_year)
copyright = f"{copyright_year}, NVIDIA CORPORATION & AFFILIATES. All rights reserved."
project = "Transformer Engine" # Transformer Engine root directory
copyright = "{}, NVIDIA CORPORATION & AFFILIATES. All rights reserved.".format(copyright_year) root_path = pathlib.Path(__file__).resolve().parent.parent
author = "NVIDIA CORPORATION & AFFILIATES"
# Git hash
git_sha = os.getenv("GIT_SHA") git_sha = os.getenv("GIT_SHA")
if not git_sha: if not git_sha:
try: try:
git_sha = ( git_sha = (
...@@ -44,31 +36,16 @@ if not git_sha: ...@@ -44,31 +36,16 @@ if not git_sha:
) )
except: except:
git_sha = "0000000" git_sha = "0000000"
git_sha = git_sha[:7] if len(git_sha) > 7 else git_sha git_sha = git_sha[:7] if len(git_sha) > 7 else git_sha
if "dev" in te_version: # Version
version = str(te_version + "-" + git_sha) with open(root_path / "build_tools" / "VERSION.txt", "r") as f:
_raw_version = f.readline().strip()
if "dev" in _raw_version:
version = str(_raw_version + "-" + git_sha)
else: else:
version = str(te_version) version = str(_raw_version)
release = te_version release = _raw_version
# hack: version is used for html creation, so put the version picker
# link here as well:
option_on = " selected"
option_off = ""
release_opt = option_on
option_nr = 0
version = (
version
+ """<br/>
Version select: <select onChange="window.location.href = this.value" onFocus="this.selectedIndex = {0}">
<option value="https://docs.nvidia.com/deeplearning/transformer-engine/user-guide/index.html"{1}>Current release</option>
<option value="https://docs.nvidia.com/deeplearning/transformer-engine/documentation-archive.html">Older releases</option>
</select>""".format(
option_nr, release_opt
)
)
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
...@@ -92,12 +69,10 @@ master_doc = "index" ...@@ -92,12 +69,10 @@ master_doc = "index"
pygments_style = "sphinx" pygments_style = "sphinx"
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = "sphinx_rtd_theme" html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
html_static_path = ["_static"] html_static_path = ["_static"]
html_show_sphinx = False html_show_sphinx = False
...@@ -106,7 +81,12 @@ html_css_files = [ ...@@ -106,7 +81,12 @@ html_css_files = [
"css/nvidia_footer.css", "css/nvidia_footer.css",
] ]
html_theme_options = {"display_version": True, "collapse_navigation": False, "logo_only": False} html_theme_options = {
"collapse_navigation": False,
"logo_only": False,
"version_selector": False,
"language_selector": False,
}
napoleon_custom_sections = [ napoleon_custom_sections = [
("Parallelism parameters", "params_style"), ("Parallelism parameters", "params_style"),
...@@ -116,8 +96,8 @@ napoleon_custom_sections = [ ...@@ -116,8 +96,8 @@ napoleon_custom_sections = [
("FP8-related parameters", "params_style"), ("FP8-related parameters", "params_style"),
] ]
breathe_projects = {"TransformerEngine": os.path.abspath("doxygen/xml/")} breathe_projects = {"TransformerEngine": root_path / "docs" / "doxygen" / "xml"}
breathe_default_project = "TransformerEngine" breathe_default_project = "TransformerEngine"
autoapi_generate_api_docs = False autoapi_generate_api_docs = False
autoapi_dirs = ["../transformer_engine"] autoapi_dirs = [root_path / "transformer_engine"]
diff --git a/sphinx_rtd_theme/layout.html b/sphinx_rtd_theme/layout.html
index e6a38b1..579eaec 100644
--- a/sphinx_rtd_theme/layout.html
+++ b/sphinx_rtd_theme/layout.html
@@ -124,6 +124,16 @@
{%- endif %}
</a>
+ {# Show TE version and version selector #}
+ <div class="version">
+ {{ version }}
+ <br>
+ Version select: <select onChange="window.location.href = this.value" onFocus="this.selectedIndex = {0}">
+ <option value="https://docs.nvidia.com/deeplearning/transformer-engine/user-guide/index.html"{1}>Current release</option>
+ <option value="https://docs.nvidia.com/deeplearning/transformer-engine/documentation-archive.html">Older releases</option>
+ </select>
+ </div>
+
{%- if READTHEDOCS or DEBUG %}
{%- if theme_version_selector or theme_language_selector %}
<div class="switch-menus">
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment