Skip to content

Commit 2fc656f

Browse files
committed
Update
1 parent 21c1978 commit 2fc656f

File tree

1 file changed

+120
-87
lines changed

1 file changed

+120
-87
lines changed

conf.py

Lines changed: 120 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,44 @@
2929
#
3030
import os
3131
import sys
32-
sys.path.insert(0, os.path.abspath('.'))
33-
sys.path.insert(0, os.path.abspath('./.jenkins'))
34-
import pytorch_sphinx_theme
35-
import torch
36-
import numpy
32+
33+
sys.path.insert(0, os.path.abspath("."))
34+
sys.path.insert(0, os.path.abspath("./.jenkins"))
35+
import distutils.file_util
3736
import gc
3837
import glob
3938
import random
40-
import shutil
41-
from custom_directives import IncludeDirective, GalleryItemDirective, CustomGalleryItemDirective, CustomCalloutItemDirective, CustomCardItemDirective
42-
import distutils.file_util
4339
import re
44-
from get_sphinx_filenames import SPHINX_SHOULD_RUN
40+
import shutil
41+
from pathlib import Path
42+
43+
import numpy
4544
import pandocfilters
46-
import pypandoc
4745
import plotly.io as pio
48-
from pathlib import Path
49-
pio.renderers.default = 'sphinx_gallery'
46+
import pypandoc
47+
import pytorch_sphinx_theme
48+
import torch
49+
from custom_directives import (
50+
CustomCalloutItemDirective,
51+
CustomCardItemDirective,
52+
CustomGalleryItemDirective,
53+
GalleryItemDirective,
54+
IncludeDirective,
55+
)
56+
from get_sphinx_filenames import SPHINX_SHOULD_RUN
57+
58+
pio.renderers.default = "sphinx_gallery"
5059

5160

5261
try:
5362
import torchvision
5463
except ImportError:
5564
import warnings
65+
5666
warnings.warn('unable to load "torchvision" package')
5767
import pytorch_sphinx_theme
5868

59-
rst_epilog ="""
69+
rst_epilog = """
6070
.. |edit| image:: /_static/pencil-16.png
6171
:width: 16px
6272
:height: 16px
@@ -69,21 +79,21 @@
6979
# needs_sphinx = '1.0'
7080

7181
html_meta = {
72-
'description': 'Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!',
73-
'keywords': 'PyTorch, tutorials, Getting Started, deep learning, AI',
74-
'author': 'PyTorch Contributors'
82+
"description": "Master PyTorch with our step-by-step tutorials for all skill levels. Start your journey to becoming a PyTorch expert today!",
83+
"keywords": "PyTorch, tutorials, Getting Started, deep learning, AI",
84+
"author": "PyTorch Contributors",
7585
}
7686

7787
# Add any Sphinx extension module names here, as strings. They can be
7888
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
7989
# ones.
8090
extensions = [
81-
'sphinxcontrib.katex',
82-
'sphinx.ext.intersphinx',
83-
'sphinx_copybutton',
84-
'sphinx_gallery.gen_gallery',
85-
'sphinx_design',
86-
'sphinx_sitemap'
91+
"sphinxcontrib.katex",
92+
"sphinx.ext.intersphinx",
93+
"sphinx_copybutton",
94+
"sphinx_gallery.gen_gallery",
95+
"sphinx_design",
96+
"sphinx_sitemap",
8797
]
8898

8999

@@ -98,52 +108,64 @@
98108

99109
# -- Sphinx-gallery configuration --------------------------------------------
100110

111+
101112
def reset_seeds(gallery_conf, fname):
102113
torch.cuda.empty_cache()
103114
torch.manual_seed(42)
104115
torch.set_default_device(None)
105116
random.seed(10)
106117
numpy.random.seed(10)
107118
gc.collect()
108-
torch._dynamo()
119+
torch._dynamo.reset()
109120
torch._inductor.clear_compile_cache()
110121

122+
111123
sphinx_gallery_conf = {
112-
'examples_dirs': ['beginner_source', 'intermediate_source',
113-
'advanced_source', 'recipes_source', 'prototype_source'],
114-
'gallery_dirs': ['beginner', 'intermediate', 'advanced', 'recipes', 'prototype'],
115-
'filename_pattern': re.compile(SPHINX_SHOULD_RUN),
116-
'promote_jupyter_magic': True,
117-
'backreferences_dir': None,
118-
'first_notebook_cell': ("# For tips on running notebooks in Google Colab, see\n"
119-
"# https://pytorch.org/tutorials/beginner/colab\n"
120-
"%matplotlib inline"),
121-
'reset_modules': (reset_seeds),
122-
'ignore_pattern': r'_torch_export_nightly_tutorial.py',
123-
'pypandoc': {'extra_args': ['--mathjax', '--toc'],
124-
'filters': ['.jenkins/custom_pandoc_filter.py'],
124+
"examples_dirs": [
125+
"beginner_source",
126+
"intermediate_source",
127+
"advanced_source",
128+
"recipes_source",
129+
"prototype_source",
130+
],
131+
"gallery_dirs": ["beginner", "intermediate", "advanced", "recipes", "prototype"],
132+
"filename_pattern": re.compile(SPHINX_SHOULD_RUN),
133+
"promote_jupyter_magic": True,
134+
"backreferences_dir": None,
135+
"first_notebook_cell": (
136+
"# For tips on running notebooks in Google Colab, see\n"
137+
"# https://pytorch.org/tutorials/beginner/colab\n"
138+
"%matplotlib inline"
139+
),
140+
"reset_modules": (reset_seeds),
141+
"ignore_pattern": r"_torch_export_nightly_tutorial.py",
142+
"pypandoc": {
143+
"extra_args": ["--mathjax", "--toc"],
144+
"filters": [".jenkins/custom_pandoc_filter.py"],
125145
},
126146
}
127147

128-
html_baseurl = 'https://pytorch.org/tutorials/' # needed for sphinx-sitemap
148+
html_baseurl = "https://pytorch.org/tutorials/" # needed for sphinx-sitemap
129149
sitemap_locales = [None]
130150
sitemap_excludes = [
131151
"search.html",
132152
"genindex.html",
133153
]
134154
sitemap_url_scheme = "{link}"
135155

136-
if os.getenv('GALLERY_PATTERN'):
156+
if os.getenv("GALLERY_PATTERN"):
137157
# GALLERY_PATTERN is to be used when you want to work on a single
138158
# tutorial. Previously this was fed into filename_pattern, but
139159
# if you do that, you still end up parsing all of the other Python
140160
# files which takes a few seconds. This strategy is better, as
141161
# ignore_pattern also skips parsing.
142162
# See https://github.com/sphinx-gallery/sphinx-gallery/issues/721
143163
# for a more detailed description of the issue.
144-
sphinx_gallery_conf['ignore_pattern'] = r'/(?!' + re.escape(os.getenv('GALLERY_PATTERN')) + r')[^/]+$'
164+
sphinx_gallery_conf["ignore_pattern"] = (
165+
r"/(?!" + re.escape(os.getenv("GALLERY_PATTERN")) + r")[^/]+$"
166+
)
145167

146-
for i in range(len(sphinx_gallery_conf['examples_dirs'])):
168+
for i in range(len(sphinx_gallery_conf["examples_dirs"])):
147169
gallery_dir = Path(sphinx_gallery_conf["gallery_dirs"][i])
148170
source_dir = Path(sphinx_gallery_conf["examples_dirs"][i])
149171

@@ -155,21 +177,21 @@ def reset_seeds(gallery_conf, fname):
155177
distutils.file_util.copy_file(f, gallery_subdir_path, update=True)
156178

157179
# Add any paths that contain templates here, relative to this directory.
158-
templates_path = ['_templates']
180+
templates_path = ["_templates"]
159181

160182
# The suffix(es) of source filenames.
161183
# You can specify multiple suffix as a list of string:
162184
#
163185
# source_suffix = ['.rst', '.md']
164-
source_suffix = '.rst'
186+
source_suffix = ".rst"
165187

166188
# The master toctree document.
167-
master_doc = 'index'
189+
master_doc = "index"
168190

169191
# General information about the project.
170-
project = 'PyTorch Tutorials'
171-
copyright = '2024, PyTorch'
172-
author = 'PyTorch contributors'
192+
project = "PyTorch Tutorials"
193+
copyright = "2024, PyTorch"
194+
author = "PyTorch contributors"
173195

174196
# The version info for the project you're documenting, acts as replacement for
175197
# |version| and |release|, also used in various other places throughout the
@@ -185,17 +207,22 @@ def reset_seeds(gallery_conf, fname):
185207
#
186208
# This is also used if you do content translation via gettext catalogs.
187209
# Usually you set "language" from the command line for these cases.
188-
language = 'en'
210+
language = "en"
189211

190212
# List of patterns, relative to source directory, that match files and
191213
# directories to ignore when looking for source files.
192214
# This patterns also effect to html_static_path and html_extra_path
193-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'src/pytorch-sphinx-theme/docs*']
194-
exclude_patterns += sphinx_gallery_conf['examples_dirs']
195-
exclude_patterns += ['*/index.rst']
215+
exclude_patterns = [
216+
"_build",
217+
"Thumbs.db",
218+
".DS_Store",
219+
"src/pytorch-sphinx-theme/docs*",
220+
]
221+
exclude_patterns += sphinx_gallery_conf["examples_dirs"]
222+
exclude_patterns += ["*/index.rst"]
196223

197224
# The name of the Pygments (syntax highlighting) style to use.
198-
pygments_style = 'sphinx'
225+
pygments_style = "sphinx"
199226

200227
# If true, `todo` and `todoList` produce output, else they produce nothing.
201228
todo_include_todos = False
@@ -223,7 +250,7 @@ def reset_seeds(gallery_conf, fname):
223250
# # Add any paths that contain custom static files (such as style sheets) here,
224251
# # relative to this directory. They are copied after the builtin static files,
225252
# # so a file named "default.css" will overwrite the builtin "default.css".
226-
html_static_path = ['_static']
253+
html_static_path = ["_static"]
227254

228255
# # Custom sidebar templates, maps document names to template names.
229256
# html_sidebars = {
@@ -232,23 +259,23 @@ def reset_seeds(gallery_conf, fname):
232259
# }
233260

234261

235-
html_theme = 'pytorch_sphinx_theme'
262+
html_theme = "pytorch_sphinx_theme"
236263
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
237-
html_logo = '_static/img/pytorch-logo-dark.svg'
264+
html_logo = "_static/img/pytorch-logo-dark.svg"
238265
html_theme_options = {
239-
'pytorch_project': 'tutorials',
240-
'collapse_navigation': False,
241-
'display_version': True,
242-
'navigation_with_keys': True,
243-
'logo_only': False,
244-
'analytics_id': 'GTM-T8XT4PS',
266+
"pytorch_project": "tutorials",
267+
"collapse_navigation": False,
268+
"display_version": True,
269+
"navigation_with_keys": True,
270+
"logo_only": False,
271+
"analytics_id": "GTM-T8XT4PS",
245272
}
246273

247274

248275
# -- Options for HTMLHelp output ------------------------------------------
249276

250277
# Output file base name for HTML help builder.
251-
htmlhelp_basename = 'PyTorchTutorialsdoc'
278+
htmlhelp_basename = "PyTorchTutorialsdoc"
252279

253280

254281
# -- Options for LaTeX output ---------------------------------------------
@@ -257,15 +284,12 @@ def reset_seeds(gallery_conf, fname):
257284
# The paper size ('letterpaper' or 'a4paper').
258285
#
259286
# 'papersize': 'letterpaper',
260-
261287
# The font size ('10pt', '11pt' or '12pt').
262288
#
263289
# 'pointsize': '10pt',
264-
265290
# Additional stuff for the LaTeX preamble.
266291
#
267292
# 'preamble': '',
268-
269293
# Latex figure (float) alignment
270294
#
271295
# 'figure_align': 'htbp',
@@ -275,19 +299,21 @@ def reset_seeds(gallery_conf, fname):
275299
# (source start file, target name, title,
276300
# author, documentclass [howto, manual, or own class]).
277301
latex_documents = [
278-
(master_doc, 'PyTorchTutorials.tex', 'PyTorch Tutorials',
279-
'Sasank, PyTorch contributors', 'manual'),
302+
(
303+
master_doc,
304+
"PyTorchTutorials.tex",
305+
"PyTorch Tutorials",
306+
"Sasank, PyTorch contributors",
307+
"manual",
308+
),
280309
]
281310

282311

283312
# -- Options for manual page output ---------------------------------------
284313

285314
# One entry per manual page. List of tuples
286315
# (source start file, name, description, authors, manual section).
287-
man_pages = [
288-
(master_doc, 'pytorchtutorials', 'PyTorch Tutorials',
289-
[author], 1)
290-
]
316+
man_pages = [(master_doc, "pytorchtutorials", "PyTorch Tutorials", [author], 1)]
291317

292318

293319
# -- Options for Texinfo output -------------------------------------------
@@ -296,40 +322,47 @@ def reset_seeds(gallery_conf, fname):
296322
# (source start file, target name, title, author,
297323
# dir menu entry, description, category)
298324
texinfo_documents = [
299-
(master_doc, 'PyTorchTutorials', 'PyTorch Tutorials',
300-
author, 'PyTorchTutorials', 'One line description of project.',
301-
'Miscellaneous'),
325+
(
326+
master_doc,
327+
"PyTorchTutorials",
328+
"PyTorch Tutorials",
329+
author,
330+
"PyTorchTutorials",
331+
"One line description of project.",
332+
"Miscellaneous",
333+
),
302334
]
303335

304336
html_css_files = [
305-
'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
306-
'css/custom.css',
307-
'css/custom2.css'
308-
]
337+
"https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css",
338+
"css/custom.css",
339+
"css/custom2.css",
340+
]
309341

310342
html_js_files = [
311343
"js/custom.js",
312344
]
313345

346+
314347
def setup(app):
315348
# NOTE: in Sphinx 1.8+ `html_css_files` is an official configuration value
316349
# and can be moved outside of this function (and the setup(app) function
317350
# can be deleted).
318-
#html_css_files = [
351+
# html_css_files = [
319352
# 'https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css',
320353
# 'css/custom.css'
321-
#]
354+
# ]
322355
# In Sphinx 1.8 it was renamed to `add_css_file`, 1.7 and prior it is
323356
# `add_stylesheet` (deprecated in 1.8).
324-
#add_css = getattr(app, 'add_css_file', app.add_stylesheet)
325-
#for css_file in html_css_files:
357+
# add_css = getattr(app, 'add_css_file', app.add_stylesheet)
358+
# for css_file in html_css_files:
326359
# add_css(css_file)
327360
# Custom CSS
328-
#app.add_stylesheet('css/pytorch_theme.css')
361+
# app.add_stylesheet('css/pytorch_theme.css')
329362
# app.add_stylesheet('https://fonts.googleapis.com/css?family=Lato')
330363
# Custom directives
331-
app.add_directive('includenodoc', IncludeDirective)
332-
app.add_directive('galleryitem', GalleryItemDirective)
333-
app.add_directive('customgalleryitem', CustomGalleryItemDirective)
334-
app.add_directive('customcarditem', CustomCardItemDirective)
335-
app.add_directive('customcalloutitem', CustomCalloutItemDirective)
364+
app.add_directive("includenodoc", IncludeDirective)
365+
app.add_directive("galleryitem", GalleryItemDirective)
366+
app.add_directive("customgalleryitem", CustomGalleryItemDirective)
367+
app.add_directive("customcarditem", CustomCardItemDirective)
368+
app.add_directive("customcalloutitem", CustomCalloutItemDirective)

0 commit comments

Comments
 (0)