Skip to content

Commit 72f40ba

Browse files
committed
Update to new PT Theme
stack-info: PR: #2361, branch: drisspg/stack/76
1 parent e4f2715 commit 72f40ba

File tree

5 files changed

+211
-67
lines changed

5 files changed

+211
-67
lines changed

docs/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# torchao Documentation
2+
3+
This directory contains the source files for the torchao documentation.
4+
5+
## Building the Documentation
6+
7+
### Prerequisites
8+
9+
Install the required dependencies:
10+
11+
```bash
12+
pip install -r requirements.txt
13+
pip install sphinx-serve
14+
```
15+
16+
### Build the Documentation
17+
18+
To build the HTML documentation:
19+
20+
```bash
21+
make html
22+
```
23+
24+
The built documentation will be in the `build/html` directory.
25+
26+
### Serve the Documentation Locally
27+
28+
After building, you can serve the documentation locally using `sphinx-serve`:
29+
30+
```bash
31+
sphinx-serve -b build
32+
```
33+
34+
This will start a local server (typically at http://localhost:8000) where you can view the documentation with live reload capabilities.
35+
36+
## Documentation Structure
37+
38+
- `source/` - Source files for the documentation
39+
- `conf.py` - Sphinx configuration file
40+
- `index.rst` - Main documentation entry point
41+
- `tutorials.rst` - Tutorials section index
42+
- `_static/` - Static files (CSS, images, etc.)
43+
- `_templates/` - Custom templates
44+
- `tutorials_source/` - Executable tutorial Python files (for sphinx-gallery)
45+
- `tutorials/` - Generated tutorial gallery (auto-generated, don't edit)
46+
- `build/` - Generated documentation output (created after building)
47+
48+
## Tutorial Types
49+
50+
This documentation has two types of tutorials:
51+
52+
### 1. Static Tutorials
53+
Educational content, guides, and explanations that are written as `.rst` or `.md` files:
54+
- Located directly in `source/` (e.g., `serialization.rst`, `subclass_basic.rst`)
55+
- Referenced in `source/tutorials.rst`
56+
- These are traditional documentation pages
57+
58+
### 2. Executable Tutorials
59+
Interactive code examples and demos that can be run:
60+
- Source files: `source/tutorials_source/*.py` (Python scripts with special formatting)
61+
- Generated output: `source/tutorials/` (auto-generated HTML gallery)
62+
- Built using sphinx-gallery extension
63+
- Each Python file becomes a downloadable notebook and HTML page
64+
65+
When you run `make html`, sphinx-gallery automatically converts Python files in `tutorials_source/` into an interactive gallery in the `tutorials/` directory.

docs/README.txt

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/requirements.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
sphinx-gallery>0.11
2-
sphinx==5.0.0
3-
sphinx_design
4-
sphinx_copybutton
5-
sphinx-tabs
6-
matplotlib
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+
docutils==0.17.1 # Changed from 0.16 to match sphinx-tabs requirement
6+
sphinx-design==0.4.0
7+
sphinxcontrib-mermaid==1.0.0
8+
myst-parser==0.18.1 # if want to contribute in markdown
9+
sphinx-gallery==0.11.1 # if hosting interactive tutorials
10+
sphinx-tabs==3.4.0
11+
sphinx-copybutton==0.5.2
12+
sphinx-sitemap==2.6.0
713
myst-parser
814
sphinxcontrib-mermaid==1.0.0
9-
-e git+https://github.com/pytorch/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme

docs/source/_templates/layout.html

Lines changed: 0 additions & 34 deletions
This file was deleted.

docs/source/conf.py

Lines changed: 134 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,15 @@
1616
# add these directories to sys.path here. If the directory is relative to the
1717
# documentation root, use os.path.abspath to make it absolute, like shown here.
1818
#
19-
# import os
20-
# import sys
21-
# sys.path.insert(0, os.path.abspath('.'))
2219

2320
import os
2421
import sys
2522

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

29-
sys.path.append(os.path.abspath("."))
26+
html_theme = "pytorch_sphinx_theme2"
27+
html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()]
3028

3129
# -- General configuration ------------------------------------------------
3230

@@ -46,18 +44,22 @@
4644
"sphinx.ext.napoleon",
4745
"sphinx.ext.viewcode",
4846
"sphinx.ext.duration",
47+
"sphinx.ext.linkcode",
4948
"sphinx_tabs.tabs",
5049
"sphinx_design",
5150
"sphinx_gallery.gen_gallery",
5251
"sphinx_copybutton",
5352
"myst_parser",
5453
"sphinxcontrib.mermaid",
54+
"sphinx_sitemap",
55+
"pytorch_sphinx_theme2",
56+
"sphinxext.opengraph",
5557
]
5658

5759
sphinx_gallery_conf = {
58-
"examples_dirs": "tutorials_source", # path to your sphinx-gallery examples
59-
"gallery_dirs": "tutorials", # path to where to save shpinx-gallery generated output
60-
"filename_pattern": "./*.py", # any .py file in docs/source/tutorials will be built by sphinx-gallery
60+
"examples_dirs": "tutorials_source", # path to your sphinx-gallery examples source
61+
"gallery_dirs": "tutorials", # path to where to save sphinx-gallery generated output
62+
"filename_pattern": "./*.py", # any .py file in tutorials_source will be built by sphinx-gallery
6163
"backreferences_dir": "gen_modules/backreferences", # path to store the backreferences
6264
"remove_config_comments": True,
6365
}
@@ -73,6 +75,10 @@
7375
napoleon_google_docstring = True
7476
project = "torchao"
7577

78+
# -- OpenGraph Protocol settings --
79+
ogp_site_url = "http://pytorch.org/ao"
80+
ogp_image = "https://pytorch.org/assets/images/social-share.jpg"
81+
7682
# Get TORCHAO_VERSION_DOCS during the build.
7783
torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
7884
print(f"torchao_version_docs: {torchao_version_docs}")
@@ -92,8 +98,18 @@
9298
print(f"Version: {version}")
9399
html_title = " ".join((project, version, "documentation"))
94100

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

98114
# The suffix(es) of source filenames.
99115
# You can specify multiple suffix as a list of string:
@@ -103,6 +119,16 @@
103119
".md": "markdown",
104120
}
105121

122+
# Myst-markdown configuration
123+
myst_enable_extensions = [
124+
"colon_fence",
125+
"deflist",
126+
"html_image",
127+
]
128+
129+
# Mermaid configuration
130+
# mermaid_output_format = "raw" # Commented out - may cause rendering issues
131+
106132
# The master toctree document.
107133
master_doc = "index"
108134

@@ -134,25 +160,69 @@
134160
# The theme to use for HTML and HTML Help pages. See the documentation for
135161
# a list of builtin themes.
136162
#
137-
html_theme = "pytorch_sphinx_theme"
138-
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
163+
# Theme configuration is set earlier in the file (lines 29-30)
139164

140165
# Theme options are theme-specific and customize the look and feel of a theme
141166
# further. For a list of options available for each theme, see the
142167
# documentation.
143168
#
144169
html_theme_options = {
145-
"collapse_navigation": False,
170+
"navigation_with_keys": False,
171+
"analytics_id": "GTM-T8XT4PS",
172+
"icon_links": [
173+
{
174+
"name": "X",
175+
"url": "https://x.com/PyTorch",
176+
"icon": "fa-brands fa-x-twitter",
177+
},
178+
{
179+
"name": "GitHub",
180+
"url": "https://github.com/pytorch/ao",
181+
"icon": "fa-brands fa-github",
182+
},
183+
{
184+
"name": "Discourse",
185+
"url": "https://dev-discuss.pytorch.org/",
186+
"icon": "fa-brands fa-discourse",
187+
},
188+
{
189+
"name": "PyPi",
190+
"url": "https://pypi.org/project/torchao/",
191+
"icon": "fa-brands fa-python",
192+
},
193+
],
194+
"use_edit_page_button": True,
195+
"navbar_center": "navbar-nav",
196+
# Option 2: Display version in navbar (since torchao is relatively new)
197+
"navbar_start": ["pytorch_version"],
146198
"display_version": True,
147-
"logo_only": True,
148-
"pytorch_project": "docs",
149-
"navigation_with_keys": True,
199+
"announcement": None,
150200
}
151201

152202
html_logo = "_static/img/pytorch-logo-dark.svg"
153203

154204
html_css_files = ["css/custom.css"]
155205

206+
# Base URL for sitemap generation
207+
html_baseurl = "https://pytorch.org/ao/"
208+
209+
# Configure date info for "Created On | Last Updated" feature
210+
html_context = {
211+
"date_info": {
212+
# Optional: Add paths to skip for performance optimization
213+
"paths_to_skip": [
214+
"gen_modules/", # Skip auto-generated API reference modules
215+
"tutorials/", # Skip auto-generated tutorial gallery
216+
],
217+
},
218+
"theme_variables": theme_variables,
219+
"display_github": True,
220+
"github_user": "pytorch",
221+
"github_repo": "ao",
222+
"github_version": "main",
223+
"doc_path": "docs/source",
224+
}
225+
156226
# Add any paths that contain custom static files (such as style sheets) here,
157227
# relative to this directory. They are copied after the builtin static files,
158228
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -177,8 +247,52 @@
177247
# See http://stackoverflow.com/a/41184353/3343043
178248

179249

180-
from custom_directives import CustomCardEnd, CustomCardItem, CustomCardStart
250+
# Custom directives are now handled by pytorch_sphinx_theme2
251+
# No need to register them manually
252+
253+
254+
import inspect
255+
256+
257+
def linkcode_resolve(domain, info):
258+
"""Link API objects to GitHub source code."""
259+
if domain != "py":
260+
return None
261+
if not info["module"]:
262+
return None
263+
264+
try:
265+
# Import torchao module
266+
import torchao
267+
268+
module = __import__(info["module"], fromlist=[""])
269+
obj = module
270+
for part in info["fullname"].split("."):
271+
obj = getattr(obj, part)
272+
# Get the source file and line number
273+
obj = inspect.unwrap(obj)
274+
fn = inspect.getsourcefile(obj)
275+
_, lineno = inspect.getsourcelines(obj)
276+
except Exception:
277+
return None
278+
279+
# Get the relative path from the torchao package
280+
try:
281+
fn = os.path.relpath(fn, start=os.path.dirname(torchao.__file__))
282+
except Exception:
283+
return None
284+
285+
# Determine the tag/branch based on the version
286+
if RELEASE and version != "main":
287+
# For release versions, use the version tag
288+
tag = f"v{version}"
289+
else:
290+
# For development versions, use main branch
291+
tag = "main"
292+
293+
return f"https://github.com/pytorch/ao/blob/{tag}/torchao/{fn}#L{lineno}"
294+
181295

182-
rst.directives.register_directive("customcardstart", CustomCardStart)
183-
rst.directives.register_directive("customcarditem", CustomCardItem)
184-
rst.directives.register_directive("customcardend", CustomCardEnd)
296+
def setup(app):
297+
"""Configure Sphinx app for pytorch_sphinx_theme2 features."""
298+
app.config.add_last_updated = True

0 commit comments

Comments
 (0)