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