Slicer  5.3
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
conf.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 #
3 # 3D Slicer documentation build configuration file, created by
4 # sphinx-quickstart on Tue Mar 21 03:07:30 2017.
5 #
6 # This file is execfile()d with the current directory set to its
7 # containing dir.
8 #
9 # Note that not all possible configuration values are present in this
10 # autogenerated file.
11 #
12 # All configuration values have a default; values that are commented out
13 # serve to show the default.
14 
15 # If extensions (or modules to document with autodoc) are in another directory,
16 # add these directories to sys.path here. If the directory is relative to the
17 # documentation root, use os.path.abspath to make it absolute, like shown here.
18 #
19 import lxml.etree as ET
20 import os
21 import sys
22 
23 sys.path.insert(0, os.path.abspath('../Base/Python'))
24 sys.path.append(os.path.abspath("./_sphinxext"))
25 
26 
27 # -- General configuration ------------------------------------------------
28 
29 # If your documentation needs a minimal Sphinx version, state it here.
30 #
31 # needs_sphinx = '1.0'
32 
33 # Add any Sphinx extension module names here, as strings. They can be
34 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35 # ones.
36 extensions = [
37  'sphinx.ext.autodoc',
38  'myst_parser',
39  'sphinx_markdown_tables',
40  'notfound.extension', # Show a better 404 page when an invalid address is entered
41 ]
42 
43 suppress_warnings = [
44  # Since we split the "script_repository.md" into smaller documents combined using
45  # the "include" directive, we ignore warnings like "Document headings start at H2, not H1"
46  "myst.header",
47 ]
48 
49 autodoc_mock_imports = [
50  "ctk",
51  "qt",
52  "vtk",
53 ]
54 
55 myst_enable_extensions = [
56  "colon_fence", # Allow code fence using ::: (see https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html#syntax-colon-fence)
57  "linkify", # Allow automatic creation of links from URLs (it is sufficient to write https://google.com instead of <https://google.com>)
58 ]
59 
60 # Auto-generate header anchors up to level 6, so that it can be referenced like [](file.md#header-anchor).
61 # (see https://myst-parser.readthedocs.io/en/latest/using/syntax-optional.html#auto-generated-header-anchors)
62 myst_heading_anchors = 6
63 
64 # Add any paths that contain templates here, relative to this directory.
65 templates_path = ['_templates']
66 
67 # The suffix(es) of source filenames.
68 # You can specify multiple suffix as a list of string:
69 #
70 source_suffix = ['.rst', '.md']
71 
72 # The master toctree document.
73 master_doc = 'index'
74 
75 # General information about the project.
76 project = '3D Slicer'
77 copyright = '2020, Slicer Community'
78 author = 'Slicer Community'
79 
80 # The version info for the project you're documenting, acts as replacement for
81 # |version| and |release|, also used in various other places throughout the
82 # built documents.
83 #
84 # The short X.Y version.
85 version = ''
86 # The full version, including alpha/beta/rc tags.
87 release = ''
88 
89 # The language for content autogenerated by Sphinx. Refer to documentation
90 # for a list of supported languages.
91 #
92 # This is also used if you do content translation via gettext catalogs.
93 # Usually you set "language" from the command line for these cases.
94 language = None
95 
96 # List of patterns, relative to source directory, that match files and
97 # directories to ignore when looking for source files.
98 # This patterns also effect to html_static_path and html_extra_path
99 exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '_moduledescriptions']
100 
101 # Set EXCLUDE_DEVELOPER_GUIDE=True environment variable to exclude developer guide.
102 # It is useful for quicker documentation generation while eiditing user manual.
103 if os.environ.get('EXCLUDE_API_REFERENCE', False) == 'True':
104  print("API reference is excluded from documentation.")
105  exclude_patterns.append('developer_guide/vtkTeem.rst')
106  exclude_patterns.append('developer_guide/vtkAddon.rst')
107  exclude_patterns.append('developer_guide/vtkITK.rst')
108  exclude_patterns.append('developer_guide/slicer.rst')
109  exclude_patterns.append('developer_guide/mrml.rst')
110 
111 # sphinx-notfound-page
112 # https://github.com/readthedocs/sphinx-notfound-page
113 notfound_context = {
114  'title': 'Page Not Found',
115  'body': '''
116 <h1>Page Not Found</h1>
117 <p>Sorry, we couldn't find that page.</p>
118 <p>Try using the search box or go to the homepage.</p>
119 ''',
120 }
121 
122 # The name of the Pygments (syntax highlighting) style to use.
123 pygments_style = 'sphinx'
124 
125 # If true, `todo` and `todoList` produce output, else they produce nothing.
126 todo_include_todos = False
127 
128 # A string of reStructuredText that will be included at the beginning of every source file that is read.
129 rst_prolog = open('global.rst.in').read()
130 
131 # If given, this must be the name of an image file (path relative to the configuration directory) that is the logo of the docs.
132 # It is placed at the top of the sidebar; its width should therefore not exceed 200 pixels
133 html_logo = '_static/images/3D-Slicer-Mark.png'
134 
135 # -- Options for HTML output ----------------------------------------------
136 
137 # The theme to use for HTML and HTML Help pages. See the documentation for
138 # a list of builtin themes.
139 #
140 html_theme = 'default'
141 
142 # Theme options are theme-specific and customize the look and feel of a theme
143 # further. For a list of options available for each theme, see the
144 # documentation.
145 #
146 html_theme_options = {
147  # Toc options
148  'includehidden': False,
149 }
150 
151 # Add any paths that contain custom static files (such as style sheets) here,
152 # relative to this directory. They are copied after the builtin static files,
153 # so a file named "default.css" will overwrite the builtin "default.css".
154 html_static_path = ['_static']
155 
156 # These paths are either relative to html_static_path
157 # or fully qualified paths (eg. https://...)
158 html_css_files = [
159  'css/custom.css',
160 ]
161 
162 # -- Options for HTMLHelp output ------------------------------------------
163 
164 # Output file base name for HTML help builder.
165 htmlhelp_basename = '3DSlicerdoc'
166 
167 
168 # -- Options for LaTeX output ---------------------------------------------
169 
170 latex_elements = {
171  # The paper size ('letterpaper' or 'a4paper').
172  #
173  # 'papersize': 'letterpaper',
174 
175  # The font size ('10pt', '11pt' or '12pt').
176  #
177  # 'pointsize': '10pt',
178 
179  # Additional stuff for the LaTeX preamble.
180  #
181  # 'preamble': '',
182 
183  # Latex figure (float) alignment
184  #
185  # 'figure_align': 'htbp',
186 }
187 
188 # Grouping the document tree into LaTeX files. List of tuples
189 # (source start file, target name, title,
190 # author, documentclass [howto, manual, or own class]).
191 latex_documents = [
192  (master_doc, '3DSlicer.tex', '3D Slicer Documentation',
193  'Slicer Community', 'manual'),
194 ]
195 
196 
197 # -- Options for manual page output ---------------------------------------
198 
199 # One entry per manual page. List of tuples
200 # (source start file, name, description, authors, manual section).
201 man_pages = [
202  (master_doc, '3Dslicer', '3D Slicer Documentation',
203  [author], 1)
204 ]
205 
206 
207 # -- Options for Texinfo output -------------------------------------------
208 
209 # Grouping the document tree into Texinfo files. List of tuples
210 # (source start file, target name, title, author,
211 # dir menu entry, description, category)
212 texinfo_documents = [
213  (master_doc, '3DSlicer', '3D Slicer Documentation',
214  author, '3DSlicer', 'One line description of project.',
215  'Miscellaneous'),
216 ]
217 
218 
219 # -- Read The Docs -----------------------------------------------------
220 
221 # on_rtd is whether we are on readthedocs.io
222 on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
223 
224 if not on_rtd: # only import and set the theme if we're building docs locally
225  import sphinx_rtd_theme
226  html_theme = 'sphinx_rtd_theme'
227  html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
228 
229 # -- Convert CLI module descriptions into markdown files ----------------
230 
231 # Each CLI module descriptor XML file is converted to two markdown files
232 # in _moduledescriptions subfolder: *Overview.md and *Parameters.md.
233 # Overview file contains the module title and description.
234 # Parameters file contains detailed description of module inputs and
235 # outputs, contributors, and acknowledgements.
236 #
237 # These md files are included at the top and bottom of each CLI module
238 # documentation file (user_guide\modules\*.md). Custom content, such as
239 # tutorials, screenshots, etc. can be added in between these includes.
240 #
241 # A copy of all CLI module descriptor XML files for modules that are
242 # not part of the Slicer repository (e.g., BRAINS toolkit) are stored in
243 # _extracli subfolder. Content of this folder must be updated manually
244 # whenever they are updated in the original location. The process could
245 # be automated with some effort, but since these bundled libraries do
246 # not change frequently, manual update takes less work overall.
247 
248 
249 # Documentation root folder (folder of this script).
250 docsfolder = os.path.dirname(__file__)
251 
252 # List of folders that contain CLI module descriptor XML files.
253 inputpaths = [
254  os.path.join(docsfolder, "../Modules/CLI"),
255  os.path.join(docsfolder, "_extracli"),
256 ]
257 
258 # List of modules to be excluded from documentation generation
259 # (for example, testing modules only).
260 excludenames = [
261  'CLIROITest.xml',
262  'TestGridTransformRegistration.xml',
263  'DiffusionTensorTest.xml',
264 ]
265 
266 # Output folder that contains all generated markdown files.
267 outpath = os.path.join(docsfolder, "_moduledescriptions")
268 os.makedirs(outpath, exist_ok=True)
269 with open(os.path.join(outpath, '_readme_.txt'), 'w') as descriptionfile:
270  descriptionfile.write("Content of this folder is automatically generated by Docs/conf.py from CLI module descriptor XML files\n")
271  descriptionfile.write("during documentation build. The folder can be deleted because it is automatically regenerated when needed.")
272 
273 
274 def _generatemd(dom, docsfolder, outpath, xslt, suffix):
275  """Helper function to create markdown file from CLI module description XML file using XSLT"""
276  xsltpath = os.path.join(docsfolder, xslt)
277  transform = ET.XSLT(ET.parse(xsltpath))
278  content = str(transform(dom))
279  with open(os.path.join(outpath, os.path.splitext(name)[0] + suffix + '.md'), 'w', encoding='utf8') as outfile:
280  outfile.write(content)
281 
282 
283 for inputpath in inputpaths:
284  for root, dirs, files in os.walk(inputpath):
285  for name in files:
286  if name in excludenames:
287  continue
288  if name.endswith(".xml"):
289  print(f"Generating CLI module documentation from {name}")
290  dom = ET.parse(os.path.join(root, name))
291  _generatemd(dom, docsfolder, outpath, "cli_module_overview_to_md.xsl", "Overview")
292  _generatemd(dom, docsfolder, outpath, "cli_module_parameters_to_md.xsl", "Parameters")