Skip to content

Commit 22d1539

Browse files
committed
Update to new PT Theme
stack-info: PR: #2361, branch: drisspg/stack/76
1 parent bcc6797 commit 22d1539

File tree

2 files changed

+160
-22
lines changed

2 files changed

+160
-22
lines changed

docs/requirements.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
sphinx-gallery>0.11
2-
sphinx==5.0.0
3-
sphinx_design
4-
sphinx_copybutton
5-
sphinx-tabs
6-
matplotlib
7-
myst-parser
8-
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
1+
sphinx==5.3.0
2+
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git@pytorch_sphinx_theme2#egg=pytorch_sphinx_theme2
3+
sphinxcontrib.katex==0.8.6
4+
sphinxext-opengraph==0.9.1
5+
breathe==4.34.0 # only if generating C++
6+
exhale==0.2.3 # only if generating C++ docs
7+
docutils==0.16
8+
sphinx-design==0.4.0
9+
sphinxcontrib-mermaid==0.9.2
10+
myst-parser==0.18.1 # if want to contribute in markdown
11+
sphinx-gallery==0.11.1 # if hosting interactive tutorials
12+
sphinx-tabs==3.4.0
13+
sphinx-copybutton==0.5.2
14+
sphinx-sitemap==2.6.0

docs/source/conf.py

Lines changed: 146 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import os
2424
import sys
2525

26-
import pytorch_sphinx_theme
27-
from docutils.parsers import rst
26+
sys.path.insert(0, os.path.abspath("."))
27+
import pytorch_sphinx_theme2
2828

29-
sys.path.append(os.path.abspath("."))
29+
html_theme = "pytorch_sphinx_theme2"
30+
html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()]
3031

3132
# -- General configuration ------------------------------------------------
3233

@@ -46,11 +47,16 @@
4647
"sphinx.ext.napoleon",
4748
"sphinx.ext.viewcode",
4849
"sphinx.ext.duration",
50+
"sphinx.ext.linkcode",
4951
"sphinx_tabs.tabs",
5052
"sphinx_design",
5153
"sphinx_gallery.gen_gallery",
5254
"sphinx_copybutton",
5355
"myst_parser",
56+
"sphinx_sitemap",
57+
"sphinxcontrib.mermaid",
58+
"pytorch_sphinx_theme2",
59+
"sphinxext.opengraph",
5460
]
5561

5662
sphinx_gallery_conf = {
@@ -72,6 +78,10 @@
7278
napoleon_google_docstring = True
7379
project = "torchao"
7480

81+
# -- OpenGraph Protocol settings --
82+
ogp_site_url = "http://pytorch.org/ao"
83+
ogp_image = "https://pytorch.org/assets/images/social-share.jpg"
84+
7585
# Get TORCHAO_VERSION_DOCS during the build.
7686
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
7787
print(f"torchao_version_docs: {torchao_version_docs}")
@@ -91,8 +101,18 @@
91101
print(f"Version: {version}")
92102
html_title = " ".join((project, version, "documentation"))
93103

104+
# Determine if this is a release build
105+
RELEASE = version != "main"
106+
107+
# Configure version for switcher if you have multiple versions
108+
switcher_version = "main" if not RELEASE else version
109+
94110
# Add any paths that contain templates here, relative to this directory.
95-
templates_path = ["_templates"]
111+
theme_variables = pytorch_sphinx_theme2.get_theme_variables()
112+
templates_path = [
113+
"_templates",
114+
os.path.join(os.path.dirname(pytorch_sphinx_theme2.__file__), "templates"),
115+
]
96116

97117
# The suffix(es) of source filenames.
98118
# You can specify multiple suffix as a list of string:
@@ -102,6 +122,17 @@
102122
".md": "markdown",
103123
}
104124

125+
# Myst-markdown configuration
126+
myst_enable_extensions = [
127+
"colon_fence",
128+
"deflist",
129+
"html_image",
130+
]
131+
132+
# Mermaid configuration
133+
mermaid_output_format = "raw"
134+
mermaid_init_js = "mermaid.initialize({startOnLoad:true, theme:'default'});"
135+
105136
# The master toctree document.
106137
master_doc = "index"
107138

@@ -133,25 +164,82 @@
133164
# The theme to use for HTML and HTML Help pages. See the documentation for
134165
# a list of builtin themes.
135166
#
136-
html_theme = "pytorch_sphinx_theme"
137-
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
167+
# Theme configuration is set earlier in the file (lines 29-30)
138168

139169
# Theme options are theme-specific and customize the look and feel of a theme
140170
# further. For a list of options available for each theme, see the
141171
# documentation.
142172
#
143173
html_theme_options = {
144-
"collapse_navigation": False,
174+
"navigation_with_keys": False,
175+
"analytics_id": "GTM-T8XT4PS",
176+
"logo": {
177+
"text": "",
178+
},
179+
"icon_links": [
180+
{
181+
"name": "X",
182+
"url": "https://x.com/PyTorch",
183+
"icon": "fa-brands fa-x-twitter",
184+
},
185+
{
186+
"name": "GitHub",
187+
"url": "https://github.com/pytorch/ao",
188+
"icon": "fa-brands fa-github",
189+
},
190+
{
191+
"name": "Discourse",
192+
"url": "https://dev-discuss.pytorch.org/",
193+
"icon": "fa-brands fa-discourse",
194+
},
195+
{
196+
"name": "PyPi",
197+
"url": "https://pypi.org/project/torchao/",
198+
"icon": "fa-brands fa-python",
199+
},
200+
],
201+
"use_edit_page_button": True,
202+
"navbar_center": "navbar-nav",
203+
# Option 2: Display version in navbar (since torchao is relatively new)
204+
"navbar_start": ["pytorch_version"],
145205
"display_version": True,
146-
"logo_only": True,
147-
"pytorch_project": "docs",
148-
"navigation_with_keys": True,
206+
# Uncomment below when you have multiple versions and a versions.json file
207+
# "switcher": {
208+
# "json_url": "https://pytorch.org/ao/torchao-versions.json",
209+
# "version_match": switcher_version,
210+
# },
211+
# "show_version_warning_banner": True,
149212
}
150213

151214
html_logo = "_static/img/pytorch-logo-dark.svg"
152215

153216
html_css_files = ["css/custom.css"]
154217

218+
# Base URL for sitemap generation
219+
html_baseurl = "https://pytorch.org/ao/"
220+
221+
# Configure date info for "Created On | Last Updated" feature and theme variables
222+
html_context = {
223+
"date_info": {
224+
# Optional: Add paths to skip for performance optimization
225+
"paths_to_skip": [
226+
"gen_modules/", # Skip auto-generated API reference modules
227+
"tutorials/", # Skip auto-generated tutorial gallery
228+
],
229+
},
230+
"theme_variables": theme_variables,
231+
"display_github": True,
232+
"github_url": "https://github.com",
233+
"github_user": "pytorch",
234+
"github_repo": "ao",
235+
"feedback_url": "https://github.com/pytorch/ao",
236+
"github_version": "main",
237+
"doc_path": "docs/source",
238+
"library_links": theme_variables.get("library_links", []),
239+
"community_links": theme_variables.get("community_links", []),
240+
"language_bindings_links": html_theme_options.get("language_bindings_links", []),
241+
}
242+
155243
# Add any paths that contain custom static files (such as style sheets) here,
156244
# relative to this directory. They are copied after the builtin static files,
157245
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -176,8 +264,52 @@
176264
# See http://stackoverflow.com/a/41184353/3343043
177265

178266

179-
from custom_directives import CustomCardEnd, CustomCardItem, CustomCardStart
267+
# Custom directives are now handled by pytorch_sphinx_theme2
268+
# No need to register them manually
269+
270+
271+
import inspect
272+
273+
274+
def linkcode_resolve(domain, info):
275+
"""Link API objects to GitHub source code."""
276+
if domain != "py":
277+
return None
278+
if not info["module"]:
279+
return None
280+
281+
try:
282+
# Import torchao module
283+
import torchao
284+
285+
module = __import__(info["module"], fromlist=[""])
286+
obj = module
287+
for part in info["fullname"].split("."):
288+
obj = getattr(obj, part)
289+
# Get the source file and line number
290+
obj = inspect.unwrap(obj)
291+
fn = inspect.getsourcefile(obj)
292+
_, lineno = inspect.getsourcelines(obj)
293+
except Exception:
294+
return None
295+
296+
# Get the relative path from the torchao package
297+
try:
298+
fn = os.path.relpath(fn, start=os.path.dirname(torchao.__file__))
299+
except Exception:
300+
return None
301+
302+
# Determine the tag/branch based on the version
303+
if RELEASE and version != "main":
304+
# For release versions, use the version tag
305+
tag = f"v{version}"
306+
else:
307+
# For development versions, use main branch
308+
tag = "main"
309+
310+
return f"https://github.com/pytorch/ao/blob/{tag}/torchao/{fn}#L{lineno}"
311+
180312

181-
rst.directives.register_directive("customcardstart", CustomCardStart)
182-
rst.directives.register_directive("customcarditem", CustomCardItem)
183-
rst.directives.register_directive("customcardend", CustomCardEnd)
313+
def setup(app):
314+
"""Configure Sphinx app for pytorch_sphinx_theme2 features."""
315+
app.config.add_last_updated = True

0 commit comments

Comments
 (0)