|
16 | 16 | # add these directories to sys.path here. If the directory is relative to the
|
17 | 17 | # documentation root, use os.path.abspath to make it absolute, like shown here.
|
18 | 18 | #
|
19 |
| -# import os |
20 |
| -# import sys |
21 |
| -# sys.path.insert(0, os.path.abspath('.')) |
22 | 19 |
|
23 | 20 | import os
|
24 | 21 | import sys
|
25 | 22 |
|
26 |
| -import pytorch_sphinx_theme |
27 |
| -from docutils.parsers import rst |
| 23 | +sys.path.insert(0, os.path.abspath(".")) |
| 24 | +import pytorch_sphinx_theme2 |
28 | 25 |
|
29 |
| -sys.path.append(os.path.abspath(".")) |
| 26 | +html_theme = "pytorch_sphinx_theme2" |
| 27 | +html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()] |
30 | 28 |
|
31 | 29 | # -- General configuration ------------------------------------------------
|
32 | 30 |
|
|
46 | 44 | "sphinx.ext.napoleon",
|
47 | 45 | "sphinx.ext.viewcode",
|
48 | 46 | "sphinx.ext.duration",
|
| 47 | + "sphinx.ext.linkcode", |
49 | 48 | "sphinx_tabs.tabs",
|
50 | 49 | "sphinx_design",
|
51 | 50 | "sphinx_gallery.gen_gallery",
|
52 | 51 | "sphinx_copybutton",
|
53 | 52 | "myst_parser",
|
54 | 53 | "sphinxcontrib.mermaid",
|
| 54 | + "sphinx_sitemap", |
| 55 | + "pytorch_sphinx_theme2", |
| 56 | + "sphinxext.opengraph", |
55 | 57 | ]
|
56 | 58 |
|
57 | 59 | 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 |
61 | 63 | "backreferences_dir": "gen_modules/backreferences", # path to store the backreferences
|
62 | 64 | "remove_config_comments": True,
|
63 | 65 | }
|
|
73 | 75 | napoleon_google_docstring = True
|
74 | 76 | project = "torchao"
|
75 | 77 |
|
| 78 | +# -- OpenGraph Protocol settings -- |
| 79 | +ogp_site_url = "http://pytorch.org/ao" |
| 80 | +ogp_image = "https://pytorch.org/assets/images/social-share.jpg" |
| 81 | + |
76 | 82 | # Get TORCHAO_VERSION_DOCS during the build.
|
77 | 83 | torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
|
78 | 84 | print(f"torchao_version_docs: {torchao_version_docs}")
|
|
92 | 98 | print(f"Version: {version}")
|
93 | 99 | html_title = " ".join((project, version, "documentation"))
|
94 | 100 |
|
| 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 | + |
95 | 107 | # 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 | +] |
97 | 113 |
|
98 | 114 | # The suffix(es) of source filenames.
|
99 | 115 | # You can specify multiple suffix as a list of string:
|
|
103 | 119 | ".md": "markdown",
|
104 | 120 | }
|
105 | 121 |
|
| 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 | + |
106 | 132 | # The master toctree document.
|
107 | 133 | master_doc = "index"
|
108 | 134 |
|
|
134 | 160 | # The theme to use for HTML and HTML Help pages. See the documentation for
|
135 | 161 | # a list of builtin themes.
|
136 | 162 | #
|
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) |
139 | 164 |
|
140 | 165 | # Theme options are theme-specific and customize the look and feel of a theme
|
141 | 166 | # further. For a list of options available for each theme, see the
|
142 | 167 | # documentation.
|
143 | 168 | #
|
144 | 169 | 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"], |
146 | 198 | "display_version": True,
|
147 |
| - "logo_only": True, |
148 |
| - "pytorch_project": "docs", |
149 |
| - "navigation_with_keys": True, |
| 199 | + "announcement": None, |
150 | 200 | }
|
151 | 201 |
|
152 | 202 | html_logo = "_static/img/pytorch-logo-dark.svg"
|
153 | 203 |
|
154 | 204 | html_css_files = ["css/custom.css"]
|
155 | 205 |
|
| 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 | + |
156 | 226 | # Add any paths that contain custom static files (such as style sheets) here,
|
157 | 227 | # relative to this directory. They are copied after the builtin static files,
|
158 | 228 | # so a file named "default.css" will overwrite the builtin "default.css".
|
|
177 | 247 | # See http://stackoverflow.com/a/41184353/3343043
|
178 | 248 |
|
179 | 249 |
|
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 | + |
181 | 295 |
|
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