|
9 | 9 | from docutils import transforms |
10 | 10 |
|
11 | 11 | # Change PYTHONPATH to include ${python_module_name} module and dependencies. |
12 | | -sys.path.insert(0, os.path.abspath('..')) |
| 12 | +sys.path.insert(0, os.path.abspath("..")) |
13 | 13 |
|
14 | 14 | import ${python_module_name} # pylint: disable=wrong-import-position |
15 | 15 |
|
16 | 16 | import utils.dependencies # pylint: disable=wrong-import-position |
17 | 17 |
|
18 | | - |
19 | 18 | # -- General configuration ------------------------------------------------ |
20 | 19 |
|
21 | 20 | # If your documentation needs a minimal Sphinx version, state it here. |
22 | | -needs_sphinx = '2.0.1' |
| 21 | +needs_sphinx = "2.0.1" |
23 | 22 |
|
24 | 23 | # Add any Sphinx extension module names here, as strings. They can be |
25 | 24 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
26 | 25 | # ones. |
27 | 26 | extensions = [ |
28 | | - 'recommonmark', |
29 | | - 'sphinx.ext.autodoc', |
30 | | - 'sphinx.ext.coverage', |
31 | | - 'sphinx.ext.doctest', |
32 | | - 'sphinx.ext.napoleon', |
33 | | - 'sphinx.ext.viewcode', |
34 | | - 'sphinx_markdown_tables', |
35 | | - 'sphinx_rtd_theme', |
| 27 | + "recommonmark", |
| 28 | + "sphinx.ext.autodoc", |
| 29 | + "sphinx.ext.coverage", |
| 30 | + "sphinx.ext.doctest", |
| 31 | + "sphinx.ext.napoleon", |
| 32 | + "sphinx.ext.viewcode", |
| 33 | + "sphinx_markdown_tables", |
| 34 | + "sphinx_rtd_theme", |
36 | 35 | ] |
37 | 36 |
|
38 | 37 | # We cannot install architecture dependent Python modules on readthedocs, |
39 | 38 | # therefore we mock most imports. |
40 | 39 | pip_installed_modules = set() |
41 | 40 |
|
42 | 41 | dependency_helper = utils.dependencies.DependencyHelper( |
43 | | - dependencies_file=os.path.join('..', 'dependencies.ini'), |
44 | | - test_dependencies_file=os.path.join('..', 'test_dependencies.ini')) |
| 42 | + dependencies_file=os.path.join("..", "dependencies.ini"), |
| 43 | + test_dependencies_file=os.path.join("..", "test_dependencies.ini"), |
| 44 | +) |
45 | 45 | modules_to_mock = set(dependency_helper.dependencies.keys()) |
46 | 46 | modules_to_mock = modules_to_mock.difference(pip_installed_modules) |
47 | 47 |
|
|
57 | 57 |
|
58 | 58 | # General information about the project. |
59 | 59 | # pylint: disable=redefined-builtin |
60 | | -project = '${name_description}' |
61 | | -copyright = 'The ${name_description} authors' |
| 60 | +project = "${name_description}" |
| 61 | +copyright = "The ${name_description} authors" |
62 | 62 | version = ${python_module_name}.__version__ |
63 | 63 | release = ${python_module_name}.__version__ |
64 | 64 |
|
65 | 65 | # Add any paths that contain templates here, relative to this directory. |
66 | | -templates_path = ['_templates'] |
| 66 | +templates_path = ["_templates"] |
67 | 67 |
|
68 | 68 | # List of patterns, relative to source directory, that match files and |
69 | 69 | # directories to ignore when looking for source files. |
70 | | -exclude_patterns = ['_build'] |
| 70 | +exclude_patterns = ["_build"] |
71 | 71 |
|
72 | 72 | # The master toctree document. |
73 | | -master_doc = 'index' |
| 73 | +master_doc = "index" |
74 | 74 |
|
75 | 75 | # The name of the Pygments (syntax highlighting) style to use. |
76 | | -pygments_style = 'sphinx' |
| 76 | +pygments_style = "sphinx" |
77 | 77 |
|
78 | 78 |
|
79 | 79 | # -- Options for HTML output ---------------------------------------------- |
80 | 80 |
|
81 | 81 | # The theme to use for HTML and HTML Help pages. See the documentation for |
82 | 82 | # a list of builtin themes. |
83 | | -html_theme = 'sphinx_rtd_theme' |
| 83 | +html_theme = "sphinx_rtd_theme" |
84 | 84 |
|
85 | 85 | # Output file base name for HTML help builder. |
86 | | -htmlhelp_basename = '${htmlhelp_basename}doc' |
| 86 | +htmlhelp_basename = "${htmlhelp_basename}doc" |
87 | 87 |
|
88 | 88 |
|
89 | 89 | # -- Options linkcheck ---------------------------------------------------- |
90 | 90 |
|
91 | | -linkcheck_ignore = [ |
92 | | -] |
| 91 | +linkcheck_ignore = [] |
93 | 92 |
|
94 | 93 |
|
95 | 94 | # -- Code to rewrite links for readthedocs -------------------------------- |
96 | 95 |
|
97 | 96 | # This function is a Sphinx core event callback, the format of which is detailed |
98 | 97 | # here: https://www.sphinx-doc.org/en/master/extdev/appapi.html#events |
99 | 98 |
|
| 99 | + |
100 | 100 | # pylint: disable=unused-argument |
101 | 101 | def RunSphinxAPIDoc(app): |
102 | | - """Runs sphinx-apidoc to auto-generate documentation. |
| 102 | + """Runs sphinx-apidoc to auto-generate documentation. |
103 | 103 |
|
104 | | - Args: |
105 | | - app (sphinx.application.Sphinx): Sphinx application. Required by the |
106 | | - the Sphinx event callback API. |
107 | | - """ |
108 | | - current_directory = os.path.abspath(os.path.dirname(__file__)) |
109 | | - module_path = os.path.join(current_directory, '..', '${python_module_name}') |
110 | | - api_directory = os.path.join(current_directory, 'sources', 'api') |
111 | | - apidoc.main(['-o', api_directory, module_path, '--force']) |
| 104 | + Args: |
| 105 | + app (sphinx.application.Sphinx): Sphinx application. Required by the |
| 106 | + the Sphinx event callback API. |
| 107 | + """ |
| 108 | + current_directory = os.path.abspath(os.path.dirname(__file__)) |
| 109 | + module_path = os.path.join(current_directory, "..", "${python_module_name}") |
| 110 | + api_directory = os.path.join(current_directory, "sources", "api") |
| 111 | + apidoc.main(["-o", api_directory, module_path, "--force"]) |
112 | 112 |
|
113 | 113 |
|
114 | 114 | class MarkdownLinkFixer(transforms.Transform): |
115 | | - """Transform definition to parse .md references to internal pages.""" |
| 115 | + """Transform definition to parse .md references to internal pages.""" |
116 | 116 |
|
117 | | - default_priority = 1000 |
| 117 | + default_priority = 1000 |
118 | 118 |
|
119 | | - _URI_PREFIXES = [] |
| 119 | + _URI_PREFIXES = [] |
120 | 120 |
|
121 | | - def _FixLinks(self, node): |
122 | | - """Corrects links to .md files not part of the documentation. |
| 121 | + def _FixLinks(self, node): |
| 122 | + """Corrects links to .md files not part of the documentation. |
123 | 123 |
|
124 | | - Args: |
125 | | - node (docutils.nodes.Node): docutils node. |
| 124 | + Args: |
| 125 | + node (docutils.nodes.Node): docutils node. |
126 | 126 |
|
127 | | - Returns: |
128 | | - docutils.nodes.Node: docutils node, with correct URIs outside |
129 | | - of Markdown pages outside the documentation. |
130 | | - """ |
131 | | - if isinstance(node, nodes.reference) and 'refuri' in node: |
132 | | - reference_uri = node['refuri'] |
133 | | - for uri_prefix in self._URI_PREFIXES: |
134 | | - if (reference_uri.startswith(uri_prefix) and not ( |
135 | | - reference_uri.endswith('.asciidoc') or |
136 | | - reference_uri.endswith('.md'))): |
137 | | - node['refuri'] = reference_uri + '.md' |
138 | | - break |
| 127 | + Returns: |
| 128 | + docutils.nodes.Node: docutils node, with correct URIs outside |
| 129 | + of Markdown pages outside the documentation. |
| 130 | + """ |
| 131 | + if isinstance(node, nodes.reference) and "refuri" in node: |
| 132 | + reference_uri = node["refuri"] |
| 133 | + for uri_prefix in self._URI_PREFIXES: |
| 134 | + if reference_uri.startswith(uri_prefix) and not ( |
| 135 | + reference_uri.endswith(".asciidoc") or reference_uri.endswith(".md") |
| 136 | + ): |
| 137 | + node["refuri"] = reference_uri + ".md" |
| 138 | + break |
139 | 139 |
|
140 | | - return node |
| 140 | + return node |
141 | 141 |
|
142 | | - def _Traverse(self, node): |
143 | | - """Traverses the document tree rooted at node. |
| 142 | + def _Traverse(self, node): |
| 143 | + """Traverses the document tree rooted at node. |
144 | 144 |
|
145 | | - Args: |
146 | | - node (docutils.nodes.Node): docutils node. |
147 | | - """ |
148 | | - self._FixLinks(node) |
| 145 | + Args: |
| 146 | + node (docutils.nodes.Node): docutils node. |
| 147 | + """ |
| 148 | + self._FixLinks(node) |
149 | 149 |
|
150 | | - for child_node in node.children: |
151 | | - self._Traverse(child_node) |
| 150 | + for child_node in node.children: |
| 151 | + self._Traverse(child_node) |
152 | 152 |
|
153 | | - # pylint: disable=arguments-differ |
154 | | - def apply(self): |
155 | | - """Applies this transform on document tree.""" |
156 | | - self._Traverse(self.document) |
| 153 | + # pylint: disable=arguments-differ |
| 154 | + def apply(self): |
| 155 | + """Applies this transform on document tree.""" |
| 156 | + self._Traverse(self.document) |
157 | 157 |
|
158 | 158 |
|
159 | 159 | # pylint: invalid-name |
160 | 160 | def setup(app): |
161 | | - """Called at Sphinx initialization. |
162 | | -
|
163 | | - Args: |
164 | | - app (sphinx.application.Sphinx): Sphinx application. |
165 | | - """ |
166 | | - # Triggers sphinx-apidoc to generate API documentation. |
167 | | - app.connect('builder-inited', RunSphinxAPIDoc) |
168 | | - app.add_config_value( |
169 | | - 'recommonmark_config', {'enable_auto_toc_tree': True}, True) |
170 | | - app.add_transform(MarkdownLinkFixer) |
| 161 | + """Called at Sphinx initialization. |
| 162 | +
|
| 163 | + Args: |
| 164 | + app (sphinx.application.Sphinx): Sphinx application. |
| 165 | + """ |
| 166 | + # Triggers sphinx-apidoc to generate API documentation. |
| 167 | + app.connect("builder-inited", RunSphinxAPIDoc) |
| 168 | + app.add_config_value("recommonmark_config", {"enable_auto_toc_tree": True}, True) |
| 169 | + app.add_transform(MarkdownLinkFixer) |
0 commit comments