|
23 | 23 | import os
|
24 | 24 | import sys
|
25 | 25 |
|
26 |
| -import pytorch_sphinx_theme |
27 |
| -from docutils.parsers import rst |
| 26 | +sys.path.insert(0, os.path.abspath(".")) |
| 27 | +import pytorch_sphinx_theme2 |
28 | 28 |
|
29 |
| -sys.path.append(os.path.abspath(".")) |
| 29 | +html_theme = "pytorch_sphinx_theme2" |
| 30 | +html_theme_path = [pytorch_sphinx_theme2.get_html_theme_path()] |
30 | 31 |
|
31 | 32 | # -- General configuration ------------------------------------------------
|
32 | 33 |
|
|
46 | 47 | "sphinx.ext.napoleon",
|
47 | 48 | "sphinx.ext.viewcode",
|
48 | 49 | "sphinx.ext.duration",
|
| 50 | + "sphinx.ext.linkcode", |
49 | 51 | "sphinx_tabs.tabs",
|
50 | 52 | "sphinx_design",
|
51 | 53 | "sphinx_gallery.gen_gallery",
|
52 | 54 | "sphinx_copybutton",
|
53 | 55 | "myst_parser",
|
54 | 56 | "sphinxcontrib.mermaid",
|
| 57 | + "sphinx_sitemap", |
| 58 | + "pytorch_sphinx_theme2", |
| 59 | + "sphinxext.opengraph", |
55 | 60 | ]
|
56 | 61 |
|
57 | 62 | sphinx_gallery_conf = {
|
|
73 | 78 | napoleon_google_docstring = True
|
74 | 79 | project = "torchao"
|
75 | 80 |
|
| 81 | +# -- OpenGraph Protocol settings -- |
| 82 | +ogp_site_url = "http://pytorch.org/ao" |
| 83 | +ogp_image = "https://pytorch.org/assets/images/social-share.jpg" |
| 84 | + |
76 | 85 | # Get TORCHAO_VERSION_DOCS during the build.
|
77 | 86 | torchao_version_docs = os.environ.get("TORCHAO_VERSION_DOCS", None)
|
78 | 87 | print(f"torchao_version_docs: {torchao_version_docs}")
|
|
92 | 101 | print(f"Version: {version}")
|
93 | 102 | html_title = " ".join((project, version, "documentation"))
|
94 | 103 |
|
| 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 | + |
95 | 110 | # Add any paths that contain templates here, relative to this directory.
|
96 |
| -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 | +] |
97 | 116 |
|
98 | 117 | # The suffix(es) of source filenames.
|
99 | 118 | # You can specify multiple suffix as a list of string:
|
|
103 | 122 | ".md": "markdown",
|
104 | 123 | }
|
105 | 124 |
|
| 125 | +# Myst-markdown configuration |
| 126 | +myst_enable_extensions = [ |
| 127 | + "colon_fence", |
| 128 | + "deflist", |
| 129 | + "html_image", |
| 130 | +] |
| 131 | + |
| 132 | +# Mermaid configuration - simplified |
| 133 | +mermaid_output_format = "raw" |
| 134 | + |
106 | 135 | # The master toctree document.
|
107 | 136 | master_doc = "index"
|
108 | 137 |
|
|
134 | 163 | # The theme to use for HTML and HTML Help pages. See the documentation for
|
135 | 164 | # a list of builtin themes.
|
136 | 165 | #
|
137 |
| -html_theme = "pytorch_sphinx_theme" |
138 |
| -html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()] |
| 166 | +# Theme configuration is set earlier in the file (lines 29-30) |
139 | 167 |
|
140 | 168 | # Theme options are theme-specific and customize the look and feel of a theme
|
141 | 169 | # further. For a list of options available for each theme, see the
|
142 | 170 | # documentation.
|
143 | 171 | #
|
144 | 172 | html_theme_options = {
|
145 |
| - "collapse_navigation": False, |
| 173 | + "navigation_with_keys": False, |
| 174 | + "analytics_id": "GTM-T8XT4PS", |
| 175 | + "logo": { |
| 176 | + "text": "", |
| 177 | + }, |
| 178 | + "icon_links": [ |
| 179 | + { |
| 180 | + "name": "X", |
| 181 | + "url": "https://x.com/PyTorch", |
| 182 | + "icon": "fa-brands fa-x-twitter", |
| 183 | + }, |
| 184 | + { |
| 185 | + "name": "GitHub", |
| 186 | + "url": "https://github.com/pytorch/ao", |
| 187 | + "icon": "fa-brands fa-github", |
| 188 | + }, |
| 189 | + { |
| 190 | + "name": "Discourse", |
| 191 | + "url": "https://dev-discuss.pytorch.org/", |
| 192 | + "icon": "fa-brands fa-discourse", |
| 193 | + }, |
| 194 | + { |
| 195 | + "name": "PyPi", |
| 196 | + "url": "https://pypi.org/project/torchao/", |
| 197 | + "icon": "fa-brands fa-python", |
| 198 | + }, |
| 199 | + ], |
| 200 | + "use_edit_page_button": True, |
| 201 | + "navbar_center": "navbar-nav", |
| 202 | + # Option 2: Display version in navbar (since torchao is relatively new) |
| 203 | + "navbar_start": ["pytorch_version"], |
146 | 204 | "display_version": True,
|
147 |
| - "logo_only": True, |
148 |
| - "pytorch_project": "docs", |
149 |
| - "navigation_with_keys": True, |
| 205 | + # Uncomment below when you have multiple versions and a versions.json file |
| 206 | + # "switcher": { |
| 207 | + # "json_url": "https://pytorch.org/ao/torchao-versions.json", |
| 208 | + # "version_match": switcher_version, |
| 209 | + # }, |
| 210 | + # "show_version_warning_banner": True, |
| 211 | + # Remove any announcement banner |
| 212 | + "announcement": None, |
150 | 213 | }
|
151 | 214 |
|
152 | 215 | html_logo = "_static/img/pytorch-logo-dark.svg"
|
153 | 216 |
|
154 | 217 | html_css_files = ["css/custom.css"]
|
155 | 218 |
|
| 219 | +# Remove external JS that's causing loading issues |
| 220 | +# html_js_files = [ |
| 221 | +# ("https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js", {"async": "async"}), |
| 222 | +# ] |
| 223 | + |
| 224 | +# Base URL for sitemap generation |
| 225 | +html_baseurl = "https://pytorch.org/ao/" |
| 226 | + |
| 227 | +# Configure date info for "Created On | Last Updated" feature and theme variables |
| 228 | +html_context = { |
| 229 | + "date_info": { |
| 230 | + # Optional: Add paths to skip for performance optimization |
| 231 | + "paths_to_skip": [ |
| 232 | + "gen_modules/", # Skip auto-generated API reference modules |
| 233 | + "tutorials/", # Skip auto-generated tutorial gallery |
| 234 | + ], |
| 235 | + }, |
| 236 | + "theme_variables": theme_variables, |
| 237 | + "display_github": True, |
| 238 | + "github_url": "https://github.com", |
| 239 | + "github_user": "pytorch", |
| 240 | + "github_repo": "ao", |
| 241 | + "feedback_url": "https://github.com/pytorch/ao", |
| 242 | + "github_version": "main", |
| 243 | + "doc_path": "docs/source", |
| 244 | + "library_links": theme_variables.get("library_links", []), |
| 245 | + "community_links": theme_variables.get("community_links", []), |
| 246 | + "language_bindings_links": html_theme_options.get("language_bindings_links", []), |
| 247 | +} |
| 248 | + |
156 | 249 | # Add any paths that contain custom static files (such as style sheets) here,
|
157 | 250 | # relative to this directory. They are copied after the builtin static files,
|
158 | 251 | # so a file named "default.css" will overwrite the builtin "default.css".
|
|
177 | 270 | # See http://stackoverflow.com/a/41184353/3343043
|
178 | 271 |
|
179 | 272 |
|
180 |
| -from custom_directives import CustomCardEnd, CustomCardItem, CustomCardStart |
| 273 | +# Custom directives are now handled by pytorch_sphinx_theme2 |
| 274 | +# No need to register them manually |
| 275 | + |
| 276 | + |
| 277 | +import inspect |
| 278 | + |
| 279 | + |
| 280 | +def linkcode_resolve(domain, info): |
| 281 | + """Link API objects to GitHub source code.""" |
| 282 | + if domain != "py": |
| 283 | + return None |
| 284 | + if not info["module"]: |
| 285 | + return None |
| 286 | + |
| 287 | + try: |
| 288 | + # Import torchao module |
| 289 | + import torchao |
| 290 | + |
| 291 | + module = __import__(info["module"], fromlist=[""]) |
| 292 | + obj = module |
| 293 | + for part in info["fullname"].split("."): |
| 294 | + obj = getattr(obj, part) |
| 295 | + # Get the source file and line number |
| 296 | + obj = inspect.unwrap(obj) |
| 297 | + fn = inspect.getsourcefile(obj) |
| 298 | + _, lineno = inspect.getsourcelines(obj) |
| 299 | + except Exception: |
| 300 | + return None |
| 301 | + |
| 302 | + # Get the relative path from the torchao package |
| 303 | + try: |
| 304 | + fn = os.path.relpath(fn, start=os.path.dirname(torchao.__file__)) |
| 305 | + except Exception: |
| 306 | + return None |
| 307 | + |
| 308 | + # Determine the tag/branch based on the version |
| 309 | + if RELEASE and version != "main": |
| 310 | + # For release versions, use the version tag |
| 311 | + tag = f"v{version}" |
| 312 | + else: |
| 313 | + # For development versions, use main branch |
| 314 | + tag = "main" |
| 315 | + |
| 316 | + return f"https://github.com/pytorch/ao/blob/{tag}/torchao/{fn}#L{lineno}" |
| 317 | + |
181 | 318 |
|
182 |
| -rst.directives.register_directive("customcardstart", CustomCardStart) |
183 |
| -rst.directives.register_directive("customcarditem", CustomCardItem) |
184 |
| -rst.directives.register_directive("customcardend", CustomCardEnd) |
| 319 | +def setup(app): |
| 320 | + """Configure Sphinx app for pytorch_sphinx_theme2 features.""" |
| 321 | + app.config.add_last_updated = True |
0 commit comments