We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Update sphinx to 3.5.4 or latest
## 📚 Documentation

Let's bump Sphinx version to 3.5.4 or later for our docs building.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `docs/source/conf.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 #
3 # Configuration file for the Sphinx documentation builder.
4 #
5 # This file does only contain a selection of the most common options. For a
6 # full list see the documentation:
7 # http://www.sphinx-doc.org/en/stable/config
8 
9 # -- Path setup --------------------------------------------------------------
10 
11 # If extensions (or modules to document with autodoc) are in another directory,
12 # add these directories to sys.path here. If the directory is relative to the
13 # documentation root, use os.path.abspath to make it absolute, like shown here.
14 #
15 import os
16 import sys
17 
18 sys.path.insert(0, os.path.abspath("../.."))
19 import ignite
20 import pytorch_sphinx_theme
21 
22 from datetime import datetime
23 
24 # -- Project information -----------------------------------------------------
25 
26 project = "PyTorch-Ignite"
27 author = "PyTorch-Ignite Contributors"
28 copyright = f"{datetime.now().year}, {author}"
29 
30 # The short X.Y version
31 try:
32     version = os.environ["code_version"]
33 except KeyError:
34     version = ignite.__version__
35 
36 # The full version, including alpha/beta/rc tags
37 release = version
38 
39 
40 # -- General configuration ---------------------------------------------------
41 
42 # If your documentation needs a minimal Sphinx version, state it here.
43 #
44 # needs_sphinx = '1.0'
45 
46 # Add any Sphinx extension module names here, as strings. They can be
47 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
48 # ones.
49 extensions = [
50     "sphinx.ext.autodoc",
51     "sphinx.ext.autosummary",
52     "sphinx.ext.doctest",
53     "sphinx.ext.intersphinx",
54     "sphinx.ext.todo",
55     "sphinx.ext.coverage",
56     "sphinxcontrib.katex",
57     "sphinx.ext.napoleon",
58     "sphinx.ext.viewcode",
59     "sphinx.ext.autosectionlabel",
60     "sphinx_copybutton",
61 ]
62 
63 # katex options
64 katex_prerender = True
65 
66 # Add any paths that contain templates here, relative to this directory.
67 templates_path = ["_templates"]
68 
69 # The suffix(es) of source filenames.
70 # You can specify multiple suffix as a list of string:
71 #
72 # source_suffix = ['.rst', '.md']
73 source_suffix = ".rst"
74 
75 # The master toctree document.
76 master_doc = "index"
77 
78 # The language for content autogenerated by Sphinx. Refer to documentation
79 # for a list of supported languages.
80 #
81 # This is also used if you do content translation via gettext catalogs.
82 # Usually you set "language" from the command line for these cases.
83 language = "en"
84 
85 # List of patterns, relative to source directory, that match files and
86 # directories to ignore when looking for source files.
87 # This pattern also affects html_static_path and html_extra_path .
88 exclude_patterns = []
89 
90 # The name of the Pygments (syntax highlighting) style to use.
91 pygments_style = "sphinx"
92 
93 
94 # -- Options for HTML output -------------------------------------------------
95 
96 # The theme to use for HTML and HTML Help pages.  See the documentation for
97 # a list of builtin themes.
98 
99 html_title = f"{project} {version} Documentation"
100 html_theme = "pytorch_sphinx_theme"
101 html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
102 
103 html_theme_options = {
104     "canonical_url": "https://pytorch.org/ignite/",
105     "collapse_navigation": False,
106     "display_version": True,
107     "logo_only": True,
108     "navigation_with_keys": True,
109 }
110 
111 html_logo = "_templates/_static/img/ignite_logo.svg"
112 
113 html_favicon = "_templates/_static/img/ignite_logomark.svg"
114 
115 # Theme options are theme-specific and customize the look and feel of a theme
116 # further.  For a list of options available for each theme, see the
117 # documentation.
118 #
119 # html_theme_options = {}
120 
121 # Add any paths that contain custom static files (such as style sheets) here,
122 # relative to this directory. They are copied after the builtin static files,
123 # so a file named "default.css" will overwrite the builtin "default.css".
124 html_static_path = ["_static", "_templates/_static"]
125 
126 html_context = {
127     "extra_css_files": [
128         # 'https://fonts.googleapis.com/css?family=Lato',
129         # '_static/css/pytorch_theme.css'
130         "_static/css/ignite_theme.css",
131         "https://cdn.jsdelivr.net/npm/@docsearch/css@1.0.0-alpha.28/dist/style.min.css",
132     ],
133 }
134 
135 html_last_updated_fmt = "%m/%d/%Y, %X"
136 html_add_permalinks = "#"
137 
138 # -- Options for HTMLHelp output ---------------------------------------------
139 
140 # Output file base name for HTML help builder.
141 htmlhelp_basename = "ignitedoc"
142 
143 
144 # -- Options for LaTeX output ------------------------------------------------
145 
146 latex_elements = {
147     # The paper size ('letterpaper' or 'a4paper').
148     #
149     # 'papersize': 'letterpaper',
150     # The font size ('10pt', '11pt' or '12pt').
151     #
152     # 'pointsize': '10pt',
153     # Additional stuff for the LaTeX preamble.
154     #
155     # 'preamble': '',
156     # Latex figure (float) alignment
157     #
158     # 'figure_align': 'htbp',
159 }
160 
161 # Grouping the document tree into LaTeX files. List of tuples
162 # (source start file, target name, title,
163 #  author, documentclass [howto, manual, or own class]).
164 latex_documents = [
165     (master_doc, "ignite.tex", "ignite Documentation", "Torch Contributors", "manual"),
166 ]
167 
168 
169 # -- Options for manual page output ------------------------------------------
170 
171 # One entry per manual page. List of tuples
172 # (source start file, name, description, authors, manual section).
173 man_pages = [(master_doc, "ignite", "ignite Documentation", [author], 1)]
174 
175 
176 # -- Options for Texinfo output ----------------------------------------------
177 
178 # Grouping the document tree into Texinfo files. List of tuples
179 # (source start file, target name, title, author,
180 #  dir menu entry, description, category)
181 texinfo_documents = [
182     (
183         master_doc,
184         "ignite",
185         "ignite Documentation",
186         author,
187         "ignite",
188         "One line description of project.",
189         "Miscellaneous",
190     ),
191 ]
192 
193 
194 # -- Extension configuration -------------------------------------------------
195 
196 # -- Options for intersphinx extension ---------------------------------------
197 
198 # Example configuration for intersphinx: refer to the Python standard library.
199 intersphinx_mapping = {
200     "python": ("https://docs.python.org/3", None),
201     "torch": ("https://pytorch.org/docs/stable/", None),
202 }
203 
204 # -- Options for todo extension ----------------------------------------------
205 
206 # If true, `todo` and `todoList` produce output, else they produce nothing.
207 todo_include_todos = True
208 
209 # -- Type hints configs ------------------------------------------------------
210 
211 autodoc_inherit_docstrings = True
212 autoclass_content = "both"
213 autodoc_typehints = "description"
214 napoleon_attr_annotations = True
215 
216 # -- A patch that turns-off cross refs for type annotations ------------------
217 
218 import sphinx.domains.python
219 from docutils import nodes
220 from sphinx import addnodes
221 
222 # replaces pending_xref node with desc_type for type annotations
223 sphinx.domains.python.type_to_xref = lambda t, e=None: addnodes.desc_type("", nodes.Text(t))
224 
225 # -- Autosummary patch to get list of a classes, funcs automatically ----------
226 
227 from importlib import import_module
228 from inspect import getmembers, isclass, isfunction
229 import sphinx.ext.autosummary
230 from sphinx.ext.autosummary import Autosummary
231 from docutils.parsers.rst import directives
232 from docutils.statemachine import StringList
233 
234 
235 class BetterAutosummary(Autosummary):
236     """Autosummary with autolisting for modules.
237 
238     By default it tries to import all public names (__all__),
239     otherwise import all classes and/or functions in a module.
240 
241     Options:
242     - :autolist: option to get list of classes and functions from currentmodule.
243     - :autolist-classes: option to get list of classes from currentmodule.
244     - :autolist-functions: option to get list of functions from currentmodule.
245 
246     Example Usage:
247 
248     .. currentmodule:: ignite.metrics
249 
250     .. autosummary::
251         :nosignatures:
252         :autolist:
253     """
254 
255     # Add new option
256     _option_spec = Autosummary.option_spec.copy()
257     _option_spec.update(
258         {
259             "autolist": directives.unchanged,
260             "autolist-classes": directives.unchanged,
261             "autolist-functions": directives.unchanged,
262         }
263     )
264     option_spec = _option_spec
265 
266     def run(self):
267         for auto in ("autolist", "autolist-classes", "autolist-functions"):
268             if auto in self.options:
269                 # Get current module name
270                 module_name = self.env.ref_context.get("py:module")
271                 # Import module
272                 module = import_module(module_name)
273 
274                 # Get public names (if possible)
275                 try:
276                     names = getattr(module, "__all__")
277                 except AttributeError:
278                     # Get classes defined in the module
279                     cls_names = [
280                         name[0]
281                         for name in getmembers(module, isclass)
282                         if name[-1].__module__ == module_name and not (name[0].startswith("_"))
283                     ]
284                     # Get functions defined in the module
285                     fn_names = [
286                         name[0]
287                         for name in getmembers(module, isfunction)
288                         if (name[-1].__module__ == module_name) and not (name[0].startswith("_"))
289                     ]
290                     names = cls_names + fn_names
291                     # It may happen that module doesn't have any defined class or func
292                     if not names:
293                         names = [name[0] for name in getmembers(module)]
294 
295                 # Filter out members w/o doc strings
296                 names = [name for name in names if getattr(module, name).__doc__ is not None]
297 
298                 if auto == "autolist":
299                     # Get list of all classes and functions inside module
300                     names = [
301                         name for name in names if (isclass(getattr(module, name)) or isfunction(getattr(module, name)))
302                     ]
303                 else:
304                     if auto == "autolist-classes":
305                         # Get only classes
306                         check = isclass
307                     elif auto == "autolist-functions":
308                         # Get only functions
309                         check = isfunction
310                     else:
311                         raise NotImplementedError
312 
313                     names = [name for name in names if check(getattr(module, name))]
314 
315                 # Update content
316                 self.content = StringList(names)
317         return super().run()
318 
319 
320 # Patch original Autosummary
321 sphinx.ext.autosummary.Autosummary = BetterAutosummary
322 
323 # --- autosummary config -----------------------------------------------------
324 autosummary_generate = True
325 
326 # --- nitpicky config : check internal links are correct or not --------------
327 nitpicky = True
328 # ignore links which can't be referenced
329 nitpick_ignore = [
330     ("py:class", ".."),
331     ("py:class", "TextIO"),
332     ("py:class", "torch.device"),
333     ("py:class", "_MpDeviceLoader"),
334     ("py:class", "torch.nn.modules.module.Module"),
335     ("py:class", "torch.optim.optimizer.Optimizer"),
336     ("py:class", "torch.utils.data.dataset.Dataset"),
337     ("py:class", "torch.utils.data.sampler.BatchSampler"),
338     ("py:class", "torch.cuda.amp.grad_scaler.GradScaler"),
339     ("py:class", "torch.optim.lr_scheduler._LRScheduler"),
340     ("py:class", "torch.utils.data.dataloader.DataLoader"),
341 ]
342 
343 # doctest config
344 doctest_global_setup = """
345 import torch
346 from torch import nn, optim
347 
348 from ignite.engine import *
349 from ignite.handlers import *
350 from ignite.metrics import *
351 from ignite.utils import *
352 
353 manual_seed(666)
354 """
355
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/docs/source/conf.py b/docs/source/conf.py
--- a/docs/source/conf.py
+++ b/docs/source/conf.py
@@ -16,10 +16,11 @@
 import sys
 
 sys.path.insert(0, os.path.abspath("../.."))
-import ignite
+from datetime import datetime
+
 import pytorch_sphinx_theme
 
-from datetime import datetime
+import ignite
 
 # -- Project information -----------------------------------------------------
 
@@ -133,7 +134,8 @@
 }
 
 html_last_updated_fmt = "%m/%d/%Y, %X"
-html_add_permalinks = "#"
+html_permalinks = True
+html_permalinks_icon = "#"
 
 # -- Options for HTMLHelp output ---------------------------------------------
 
@@ -213,26 +215,17 @@
 autodoc_typehints = "description"
 napoleon_attr_annotations = True
 
-# -- A patch that turns-off cross refs for type annotations ------------------
-
-import sphinx.domains.python
-from docutils import nodes
-from sphinx import addnodes
-
-# replaces pending_xref node with desc_type for type annotations
-sphinx.domains.python.type_to_xref = lambda t, e=None: addnodes.desc_type("", nodes.Text(t))
-
 # -- Autosummary patch to get list of a classes, funcs automatically ----------
 
 from importlib import import_module
 from inspect import getmembers, isclass, isfunction
-import sphinx.ext.autosummary
-from sphinx.ext.autosummary import Autosummary
+
 from docutils.parsers.rst import directives
 from docutils.statemachine import StringList
+from sphinx.ext.autosummary import Autosummary
 
 
-class BetterAutosummary(Autosummary):
+class AutolistAutosummary(Autosummary):
     """Autosummary with autolisting for modules.
 
     By default it tries to import all public names (__all__),
@@ -317,9 +310,6 @@
         return super().run()
 
 
-# Patch original Autosummary
-sphinx.ext.autosummary.Autosummary = BetterAutosummary
-
 # --- autosummary config -----------------------------------------------------
 autosummary_generate = True
 
@@ -352,3 +342,7 @@
 
 manual_seed(666)
 """
+
+
+def setup(app):
+    app.add_directive("autosummary", AutolistAutosummary, override=True)

{"golden_diff": "diff --git a/docs/source/conf.py b/docs/source/conf.py\n--- a/docs/source/conf.py\n+++ b/docs/source/conf.py\n@@ -16,10 +16,11 @@\n import sys\n \n sys.path.insert(0, os.path.abspath(\"../..\"))\n-import ignite\n+from datetime import datetime\n+\n import pytorch_sphinx_theme\n \n-from datetime import datetime\n+import ignite\n \n # -- Project information -----------------------------------------------------\n \n@@ -133,7 +134,8 @@\n }\n \n html_last_updated_fmt = \"%m/%d/%Y, %X\"\n-html_add_permalinks = \"#\"\n+html_permalinks = True\n+html_permalinks_icon = \"#\"\n \n # -- Options for HTMLHelp output ---------------------------------------------\n \n@@ -213,26 +215,17 @@\n autodoc_typehints = \"description\"\n napoleon_attr_annotations = True\n \n-# -- A patch that turns-off cross refs for type annotations ------------------\n-\n-import sphinx.domains.python\n-from docutils import nodes\n-from sphinx import addnodes\n-\n-# replaces pending_xref node with desc_type for type annotations\n-sphinx.domains.python.type_to_xref = lambda t, e=None: addnodes.desc_type(\"\", nodes.Text(t))\n-\n # -- Autosummary patch to get list of a classes, funcs automatically ----------\n \n from importlib import import_module\n from inspect import getmembers, isclass, isfunction\n-import sphinx.ext.autosummary\n-from sphinx.ext.autosummary import Autosummary\n+\n from docutils.parsers.rst import directives\n from docutils.statemachine import StringList\n+from sphinx.ext.autosummary import Autosummary\n \n \n-class BetterAutosummary(Autosummary):\n+class AutolistAutosummary(Autosummary):\n     \"\"\"Autosummary with autolisting for modules.\n \n     By default it tries to import all public names (__all__),\n@@ -317,9 +310,6 @@\n         return super().run()\n \n \n-# Patch original Autosummary\n-sphinx.ext.autosummary.Autosummary = BetterAutosummary\n-\n # --- autosummary config -----------------------------------------------------\n autosummary_generate = True\n \n@@ -352,3 +342,7 @@\n \n manual_seed(666)\n \"\"\"\n+\n+\n+def setup(app):\n+    app.add_directive(\"autosummary\", AutolistAutosummary, override=True)\n", "issue": "Update sphinx to 3.5.4 or latest\n## \ud83d\udcda Documentation\r\n\r\nLet's bump Sphinx version to 3.5.4 or later for our docs building.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Configuration file for the Sphinx documentation builder.\n#\n# This file does only contain a selection of the most common options. For a\n# full list see the documentation:\n# http://www.sphinx-doc.org/en/stable/config\n\n# -- Path setup --------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#\nimport os\nimport sys\n\nsys.path.insert(0, os.path.abspath(\"../..\"))\nimport ignite\nimport pytorch_sphinx_theme\n\nfrom datetime import datetime\n\n# -- Project information -----------------------------------------------------\n\nproject = \"PyTorch-Ignite\"\nauthor = \"PyTorch-Ignite Contributors\"\ncopyright = f\"{datetime.now().year}, {author}\"\n\n# The short X.Y version\ntry:\n    version = os.environ[\"code_version\"]\nexcept KeyError:\n    version = ignite.__version__\n\n# The full version, including alpha/beta/rc tags\nrelease = version\n\n\n# -- General configuration ---------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n#\n# needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.autosummary\",\n    \"sphinx.ext.doctest\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinx.ext.todo\",\n    \"sphinx.ext.coverage\",\n    \"sphinxcontrib.katex\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.viewcode\",\n    \"sphinx.ext.autosectionlabel\",\n    \"sphinx_copybutton\",\n]\n\n# katex options\nkatex_prerender = True\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\n# The suffix(es) of source filenames.\n# You can specify multiple suffix as a list of string:\n#\n# source_suffix = ['.rst', '.md']\nsource_suffix = \".rst\"\n\n# The master toctree document.\nmaster_doc = \"index\"\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#\n# This is also used if you do content translation via gettext catalogs.\n# Usually you set \"language\" from the command line for these cases.\nlanguage = \"en\"\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path .\nexclude_patterns = []\n\n# The name of the Pygments (syntax highlighting) style to use.\npygments_style = \"sphinx\"\n\n\n# -- Options for HTML output -------------------------------------------------\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for\n# a list of builtin themes.\n\nhtml_title = f\"{project} {version} Documentation\"\nhtml_theme = \"pytorch_sphinx_theme\"\nhtml_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]\n\nhtml_theme_options = {\n    \"canonical_url\": \"https://pytorch.org/ignite/\",\n    \"collapse_navigation\": False,\n    \"display_version\": True,\n    \"logo_only\": True,\n    \"navigation_with_keys\": True,\n}\n\nhtml_logo = \"_templates/_static/img/ignite_logo.svg\"\n\nhtml_favicon = \"_templates/_static/img/ignite_logomark.svg\"\n\n# Theme options are theme-specific and customize the look and feel of a theme\n# further.  For a list of options available for each theme, see the\n# documentation.\n#\n# html_theme_options = {}\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = [\"_static\", \"_templates/_static\"]\n\nhtml_context = {\n    \"extra_css_files\": [\n        # 'https://fonts.googleapis.com/css?family=Lato',\n        # '_static/css/pytorch_theme.css'\n        \"_static/css/ignite_theme.css\",\n        \"https://cdn.jsdelivr.net/npm/@docsearch/css@1.0.0-alpha.28/dist/style.min.css\",\n    ],\n}\n\nhtml_last_updated_fmt = \"%m/%d/%Y, %X\"\nhtml_add_permalinks = \"#\"\n\n# -- Options for HTMLHelp output ---------------------------------------------\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = \"ignitedoc\"\n\n\n# -- Options for LaTeX output ------------------------------------------------\n\nlatex_elements = {\n    # The paper size ('letterpaper' or 'a4paper').\n    #\n    # 'papersize': 'letterpaper',\n    # The font size ('10pt', '11pt' or '12pt').\n    #\n    # 'pointsize': '10pt',\n    # Additional stuff for the LaTeX preamble.\n    #\n    # 'preamble': '',\n    # Latex figure (float) alignment\n    #\n    # 'figure_align': 'htbp',\n}\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title,\n#  author, documentclass [howto, manual, or own class]).\nlatex_documents = [\n    (master_doc, \"ignite.tex\", \"ignite Documentation\", \"Torch Contributors\", \"manual\"),\n]\n\n\n# -- Options for manual page output ------------------------------------------\n\n# One entry per manual page. List of tuples\n# (source start file, name, description, authors, manual section).\nman_pages = [(master_doc, \"ignite\", \"ignite Documentation\", [author], 1)]\n\n\n# -- Options for Texinfo output ----------------------------------------------\n\n# Grouping the document tree into Texinfo files. List of tuples\n# (source start file, target name, title, author,\n#  dir menu entry, description, category)\ntexinfo_documents = [\n    (\n        master_doc,\n        \"ignite\",\n        \"ignite Documentation\",\n        author,\n        \"ignite\",\n        \"One line description of project.\",\n        \"Miscellaneous\",\n    ),\n]\n\n\n# -- Extension configuration -------------------------------------------------\n\n# -- Options for intersphinx extension ---------------------------------------\n\n# Example configuration for intersphinx: refer to the Python standard library.\nintersphinx_mapping = {\n    \"python\": (\"https://docs.python.org/3\", None),\n    \"torch\": (\"https://pytorch.org/docs/stable/\", None),\n}\n\n# -- Options for todo extension ----------------------------------------------\n\n# If true, `todo` and `todoList` produce output, else they produce nothing.\ntodo_include_todos = True\n\n# -- Type hints configs ------------------------------------------------------\n\nautodoc_inherit_docstrings = True\nautoclass_content = \"both\"\nautodoc_typehints = \"description\"\nnapoleon_attr_annotations = True\n\n# -- A patch that turns-off cross refs for type annotations ------------------\n\nimport sphinx.domains.python\nfrom docutils import nodes\nfrom sphinx import addnodes\n\n# replaces pending_xref node with desc_type for type annotations\nsphinx.domains.python.type_to_xref = lambda t, e=None: addnodes.desc_type(\"\", nodes.Text(t))\n\n# -- Autosummary patch to get list of a classes, funcs automatically ----------\n\nfrom importlib import import_module\nfrom inspect import getmembers, isclass, isfunction\nimport sphinx.ext.autosummary\nfrom sphinx.ext.autosummary import Autosummary\nfrom docutils.parsers.rst import directives\nfrom docutils.statemachine import StringList\n\n\nclass BetterAutosummary(Autosummary):\n    \"\"\"Autosummary with autolisting for modules.\n\n    By default it tries to import all public names (__all__),\n    otherwise import all classes and/or functions in a module.\n\n    Options:\n    - :autolist: option to get list of classes and functions from currentmodule.\n    - :autolist-classes: option to get list of classes from currentmodule.\n    - :autolist-functions: option to get list of functions from currentmodule.\n\n    Example Usage:\n\n    .. currentmodule:: ignite.metrics\n\n    .. autosummary::\n        :nosignatures:\n        :autolist:\n    \"\"\"\n\n    # Add new option\n    _option_spec = Autosummary.option_spec.copy()\n    _option_spec.update(\n        {\n            \"autolist\": directives.unchanged,\n            \"autolist-classes\": directives.unchanged,\n            \"autolist-functions\": directives.unchanged,\n        }\n    )\n    option_spec = _option_spec\n\n    def run(self):\n        for auto in (\"autolist\", \"autolist-classes\", \"autolist-functions\"):\n            if auto in self.options:\n                # Get current module name\n                module_name = self.env.ref_context.get(\"py:module\")\n                # Import module\n                module = import_module(module_name)\n\n                # Get public names (if possible)\n                try:\n                    names = getattr(module, \"__all__\")\n                except AttributeError:\n                    # Get classes defined in the module\n                    cls_names = [\n                        name[0]\n                        for name in getmembers(module, isclass)\n                        if name[-1].__module__ == module_name and not (name[0].startswith(\"_\"))\n                    ]\n                    # Get functions defined in the module\n                    fn_names = [\n                        name[0]\n                        for name in getmembers(module, isfunction)\n                        if (name[-1].__module__ == module_name) and not (name[0].startswith(\"_\"))\n                    ]\n                    names = cls_names + fn_names\n                    # It may happen that module doesn't have any defined class or func\n                    if not names:\n                        names = [name[0] for name in getmembers(module)]\n\n                # Filter out members w/o doc strings\n                names = [name for name in names if getattr(module, name).__doc__ is not None]\n\n                if auto == \"autolist\":\n                    # Get list of all classes and functions inside module\n                    names = [\n                        name for name in names if (isclass(getattr(module, name)) or isfunction(getattr(module, name)))\n                    ]\n                else:\n                    if auto == \"autolist-classes\":\n                        # Get only classes\n                        check = isclass\n                    elif auto == \"autolist-functions\":\n                        # Get only functions\n                        check = isfunction\n                    else:\n                        raise NotImplementedError\n\n                    names = [name for name in names if check(getattr(module, name))]\n\n                # Update content\n                self.content = StringList(names)\n        return super().run()\n\n\n# Patch original Autosummary\nsphinx.ext.autosummary.Autosummary = BetterAutosummary\n\n# --- autosummary config -----------------------------------------------------\nautosummary_generate = True\n\n# --- nitpicky config : check internal links are correct or not --------------\nnitpicky = True\n# ignore links which can't be referenced\nnitpick_ignore = [\n    (\"py:class\", \"..\"),\n    (\"py:class\", \"TextIO\"),\n    (\"py:class\", \"torch.device\"),\n    (\"py:class\", \"_MpDeviceLoader\"),\n    (\"py:class\", \"torch.nn.modules.module.Module\"),\n    (\"py:class\", \"torch.optim.optimizer.Optimizer\"),\n    (\"py:class\", \"torch.utils.data.dataset.Dataset\"),\n    (\"py:class\", \"torch.utils.data.sampler.BatchSampler\"),\n    (\"py:class\", \"torch.cuda.amp.grad_scaler.GradScaler\"),\n    (\"py:class\", \"torch.optim.lr_scheduler._LRScheduler\"),\n    (\"py:class\", \"torch.utils.data.dataloader.DataLoader\"),\n]\n\n# doctest config\ndoctest_global_setup = \"\"\"\nimport torch\nfrom torch import nn, optim\n\nfrom ignite.engine import *\nfrom ignite.handlers import *\nfrom ignite.metrics import *\nfrom ignite.utils import *\n\nmanual_seed(666)\n\"\"\"\n", "path": "docs/source/conf.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n#\n# Configuration file for the Sphinx documentation builder.\n#\n# This file does only contain a selection of the most common options. For a\n# full list see the documentation:\n# http://www.sphinx-doc.org/en/stable/config\n\n# -- Path setup --------------------------------------------------------------\n\n# If extensions (or modules to document with autodoc) are in another directory,\n# add these directories to sys.path here. If the directory is relative to the\n# documentation root, use os.path.abspath to make it absolute, like shown here.\n#\nimport os\nimport sys\n\nsys.path.insert(0, os.path.abspath(\"../..\"))\nfrom datetime import datetime\n\nimport pytorch_sphinx_theme\n\nimport ignite\n\n# -- Project information -----------------------------------------------------\n\nproject = \"PyTorch-Ignite\"\nauthor = \"PyTorch-Ignite Contributors\"\ncopyright = f\"{datetime.now().year}, {author}\"\n\n# The short X.Y version\ntry:\n    version = os.environ[\"code_version\"]\nexcept KeyError:\n    version = ignite.__version__\n\n# The full version, including alpha/beta/rc tags\nrelease = version\n\n\n# -- General configuration ---------------------------------------------------\n\n# If your documentation needs a minimal Sphinx version, state it here.\n#\n# needs_sphinx = '1.0'\n\n# Add any Sphinx extension module names here, as strings. They can be\n# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom\n# ones.\nextensions = [\n    \"sphinx.ext.autodoc\",\n    \"sphinx.ext.autosummary\",\n    \"sphinx.ext.doctest\",\n    \"sphinx.ext.intersphinx\",\n    \"sphinx.ext.todo\",\n    \"sphinx.ext.coverage\",\n    \"sphinxcontrib.katex\",\n    \"sphinx.ext.napoleon\",\n    \"sphinx.ext.viewcode\",\n    \"sphinx.ext.autosectionlabel\",\n    \"sphinx_copybutton\",\n]\n\n# katex options\nkatex_prerender = True\n\n# Add any paths that contain templates here, relative to this directory.\ntemplates_path = [\"_templates\"]\n\n# The suffix(es) of source filenames.\n# You can specify multiple suffix as a list of string:\n#\n# source_suffix = ['.rst', '.md']\nsource_suffix = \".rst\"\n\n# The master toctree document.\nmaster_doc = \"index\"\n\n# The language for content autogenerated by Sphinx. Refer to documentation\n# for a list of supported languages.\n#\n# This is also used if you do content translation via gettext catalogs.\n# Usually you set \"language\" from the command line for these cases.\nlanguage = \"en\"\n\n# List of patterns, relative to source directory, that match files and\n# directories to ignore when looking for source files.\n# This pattern also affects html_static_path and html_extra_path .\nexclude_patterns = []\n\n# The name of the Pygments (syntax highlighting) style to use.\npygments_style = \"sphinx\"\n\n\n# -- Options for HTML output -------------------------------------------------\n\n# The theme to use for HTML and HTML Help pages.  See the documentation for\n# a list of builtin themes.\n\nhtml_title = f\"{project} {version} Documentation\"\nhtml_theme = \"pytorch_sphinx_theme\"\nhtml_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]\n\nhtml_theme_options = {\n    \"canonical_url\": \"https://pytorch.org/ignite/\",\n    \"collapse_navigation\": False,\n    \"display_version\": True,\n    \"logo_only\": True,\n    \"navigation_with_keys\": True,\n}\n\nhtml_logo = \"_templates/_static/img/ignite_logo.svg\"\n\nhtml_favicon = \"_templates/_static/img/ignite_logomark.svg\"\n\n# Theme options are theme-specific and customize the look and feel of a theme\n# further.  For a list of options available for each theme, see the\n# documentation.\n#\n# html_theme_options = {}\n\n# Add any paths that contain custom static files (such as style sheets) here,\n# relative to this directory. They are copied after the builtin static files,\n# so a file named \"default.css\" will overwrite the builtin \"default.css\".\nhtml_static_path = [\"_static\", \"_templates/_static\"]\n\nhtml_context = {\n    \"extra_css_files\": [\n        # 'https://fonts.googleapis.com/css?family=Lato',\n        # '_static/css/pytorch_theme.css'\n        \"_static/css/ignite_theme.css\",\n        \"https://cdn.jsdelivr.net/npm/@docsearch/css@1.0.0-alpha.28/dist/style.min.css\",\n    ],\n}\n\nhtml_last_updated_fmt = \"%m/%d/%Y, %X\"\nhtml_permalinks = True\nhtml_permalinks_icon = \"#\"\n\n# -- Options for HTMLHelp output ---------------------------------------------\n\n# Output file base name for HTML help builder.\nhtmlhelp_basename = \"ignitedoc\"\n\n\n# -- Options for LaTeX output ------------------------------------------------\n\nlatex_elements = {\n    # The paper size ('letterpaper' or 'a4paper').\n    #\n    # 'papersize': 'letterpaper',\n    # The font size ('10pt', '11pt' or '12pt').\n    #\n    # 'pointsize': '10pt',\n    # Additional stuff for the LaTeX preamble.\n    #\n    # 'preamble': '',\n    # Latex figure (float) alignment\n    #\n    # 'figure_align': 'htbp',\n}\n\n# Grouping the document tree into LaTeX files. List of tuples\n# (source start file, target name, title,\n#  author, documentclass [howto, manual, or own class]).\nlatex_documents = [\n    (master_doc, \"ignite.tex\", \"ignite Documentation\", \"Torch Contributors\", \"manual\"),\n]\n\n\n# -- Options for manual page output ------------------------------------------\n\n# One entry per manual page. List of tuples\n# (source start file, name, description, authors, manual section).\nman_pages = [(master_doc, \"ignite\", \"ignite Documentation\", [author], 1)]\n\n\n# -- Options for Texinfo output ----------------------------------------------\n\n# Grouping the document tree into Texinfo files. List of tuples\n# (source start file, target name, title, author,\n#  dir menu entry, description, category)\ntexinfo_documents = [\n    (\n        master_doc,\n        \"ignite\",\n        \"ignite Documentation\",\n        author,\n        \"ignite\",\n        \"One line description of project.\",\n        \"Miscellaneous\",\n    ),\n]\n\n\n# -- Extension configuration -------------------------------------------------\n\n# -- Options for intersphinx extension ---------------------------------------\n\n# Example configuration for intersphinx: refer to the Python standard library.\nintersphinx_mapping = {\n    \"python\": (\"https://docs.python.org/3\", None),\n    \"torch\": (\"https://pytorch.org/docs/stable/\", None),\n}\n\n# -- Options for todo extension ----------------------------------------------\n\n# If true, `todo` and `todoList` produce output, else they produce nothing.\ntodo_include_todos = True\n\n# -- Type hints configs ------------------------------------------------------\n\nautodoc_inherit_docstrings = True\nautoclass_content = \"both\"\nautodoc_typehints = \"description\"\nnapoleon_attr_annotations = True\n\n# -- Autosummary patch to get list of a classes, funcs automatically ----------\n\nfrom importlib import import_module\nfrom inspect import getmembers, isclass, isfunction\n\nfrom docutils.parsers.rst import directives\nfrom docutils.statemachine import StringList\nfrom sphinx.ext.autosummary import Autosummary\n\n\nclass AutolistAutosummary(Autosummary):\n    \"\"\"Autosummary with autolisting for modules.\n\n    By default it tries to import all public names (__all__),\n    otherwise import all classes and/or functions in a module.\n\n    Options:\n    - :autolist: option to get list of classes and functions from currentmodule.\n    - :autolist-classes: option to get list of classes from currentmodule.\n    - :autolist-functions: option to get list of functions from currentmodule.\n\n    Example Usage:\n\n    .. currentmodule:: ignite.metrics\n\n    .. autosummary::\n        :nosignatures:\n        :autolist:\n    \"\"\"\n\n    # Add new option\n    _option_spec = Autosummary.option_spec.copy()\n    _option_spec.update(\n        {\n            \"autolist\": directives.unchanged,\n            \"autolist-classes\": directives.unchanged,\n            \"autolist-functions\": directives.unchanged,\n        }\n    )\n    option_spec = _option_spec\n\n    def run(self):\n        for auto in (\"autolist\", \"autolist-classes\", \"autolist-functions\"):\n            if auto in self.options:\n                # Get current module name\n                module_name = self.env.ref_context.get(\"py:module\")\n                # Import module\n                module = import_module(module_name)\n\n                # Get public names (if possible)\n                try:\n                    names = getattr(module, \"__all__\")\n                except AttributeError:\n                    # Get classes defined in the module\n                    cls_names = [\n                        name[0]\n                        for name in getmembers(module, isclass)\n                        if name[-1].__module__ == module_name and not (name[0].startswith(\"_\"))\n                    ]\n                    # Get functions defined in the module\n                    fn_names = [\n                        name[0]\n                        for name in getmembers(module, isfunction)\n                        if (name[-1].__module__ == module_name) and not (name[0].startswith(\"_\"))\n                    ]\n                    names = cls_names + fn_names\n                    # It may happen that module doesn't have any defined class or func\n                    if not names:\n                        names = [name[0] for name in getmembers(module)]\n\n                # Filter out members w/o doc strings\n                names = [name for name in names if getattr(module, name).__doc__ is not None]\n\n                if auto == \"autolist\":\n                    # Get list of all classes and functions inside module\n                    names = [\n                        name for name in names if (isclass(getattr(module, name)) or isfunction(getattr(module, name)))\n                    ]\n                else:\n                    if auto == \"autolist-classes\":\n                        # Get only classes\n                        check = isclass\n                    elif auto == \"autolist-functions\":\n                        # Get only functions\n                        check = isfunction\n                    else:\n                        raise NotImplementedError\n\n                    names = [name for name in names if check(getattr(module, name))]\n\n                # Update content\n                self.content = StringList(names)\n        return super().run()\n\n\n# --- autosummary config -----------------------------------------------------\nautosummary_generate = True\n\n# --- nitpicky config : check internal links are correct or not --------------\nnitpicky = True\n# ignore links which can't be referenced\nnitpick_ignore = [\n    (\"py:class\", \"..\"),\n    (\"py:class\", \"TextIO\"),\n    (\"py:class\", \"torch.device\"),\n    (\"py:class\", \"_MpDeviceLoader\"),\n    (\"py:class\", \"torch.nn.modules.module.Module\"),\n    (\"py:class\", \"torch.optim.optimizer.Optimizer\"),\n    (\"py:class\", \"torch.utils.data.dataset.Dataset\"),\n    (\"py:class\", \"torch.utils.data.sampler.BatchSampler\"),\n    (\"py:class\", \"torch.cuda.amp.grad_scaler.GradScaler\"),\n    (\"py:class\", \"torch.optim.lr_scheduler._LRScheduler\"),\n    (\"py:class\", \"torch.utils.data.dataloader.DataLoader\"),\n]\n\n# doctest config\ndoctest_global_setup = \"\"\"\nimport torch\nfrom torch import nn, optim\n\nfrom ignite.engine import *\nfrom ignite.handlers import *\nfrom ignite.metrics import *\nfrom ignite.utils import *\n\nmanual_seed(666)\n\"\"\"\n\n\ndef setup(app):\n    app.add_directive(\"autosummary\", AutolistAutosummary, override=True)\n", "path": "docs/source/conf.py"}]}