19import lxml.etree
as ET
23from datetime
import date
25sys.path.insert(0, os.path.abspath(
"../Base/Python"))
26sys.path.insert(0, os.path.abspath(
"./_ext"))
40 "sphinx_markdown_tables",
47 "sphinxcontrib.mermaid",
52 "user_guide/extensions_manager.html":
"extensions.html#extensions-manager",
61autodoc_mock_imports = [
67 "SlicerBaseLogicPython",
70myst_enable_extensions = [
80myst_heading_anchors = 6
83myst_dmath_allow_labels =
True
88 Given a Slicer source director, extract <major>.<minor> version
89 from top-level `CMakeLists.txt`.
91 Return a dictionary containing `major` and `minor` version components as strings
93 slicer_src_dir = os.path.abspath(slicer_src_dir)
95 part: re.compile(rf
'set\(Slicer_VERSION_{part.upper()} "(\d+)"\)')
96 for part
in [
"major",
"minor"]
101 cmakelists_path = os.path.join(slicer_src_dir,
"CMakeLists.txt")
102 with open(cmakelists_path)
as cmake_file:
103 for line
in cmake_file:
104 for part, pattern
in version_patterns.items():
105 match = pattern.match(line.strip())
106 if match
is not None:
107 version_parts[part] = match.group(1)
108 if len(version_parts) == len(version_patterns ):
111 if len(version_parts) != len(version_patterns):
112 raise ValueError(f
"Failed to extract version from {cmakelists_path}")
119 Determine the Doxygen documentation version to use based on the Slicer version.
121 Return Doxygen version identifier (`v<major>.<minor>` for Stable, `main` for Preview)
124 slicer_repo_dir = os.path.dirname(os.path.dirname(__file__))
128 is_even = int(version_parts[
"minor"]) % 2 == 0
129 return "v{major}.{minor}".format(**version_parts)
if is_even
else "main"
134print(f
"Slicer API documentation URL scheme: {slicerapidocs_url_scheme}")
144 "slicerapidocs": slicerapidocs_url_scheme,
149templates_path = [
"_templates"]
154source_suffix = [
".rst",
".md"]
161copyright = f
"{date.today().year}, Slicer Community"
162author =
"Slicer Community"
176exclude_patterns = [
"_build",
"Thumbs.db",
".DS_Store",
"_moduledescriptions"]
180if os.environ.get(
"EXCLUDE_API_REFERENCE",
"False") ==
"True":
181 print(
"API reference is excluded from documentation.")
182 exclude_patterns.append(
"developer_guide/vtkTeem.rst")
183 exclude_patterns.append(
"developer_guide/vtkAddon.rst")
184 exclude_patterns.append(
"developer_guide/vtkITK.rst")
185 exclude_patterns.append(
"developer_guide/slicer.rst")
186 exclude_patterns.append(
"developer_guide/mrml.rst")
191 "title":
"Page Not Found",
193<h1>Page Not Found</h1>
194<p>Sorry, we couldn't find that page.</p>
195<p>Try using the search box or go to the homepage.</p>
200pygments_style =
"sphinx"
203todo_include_todos =
False
206rst_prolog = open(
"global.rst.in").read()
210html_logo =
"_static/images/3D-Slicer-Mark.png"
217html_theme =
"sphinx_rtd_theme"
223html_theme_options = {
225 "includehidden":
False,
230 "display_github":
True,
234 "github_user":
"slicer",
235 "github_repo":
"slicer",
236 "github_version":
"main",
237 "conf_py_path":
"/Docs/",
243html_static_path = [
"_static"]
252mermaid_version =
"12.0.0"
255mermaid_light_theme =
"redux-color"
256mermaid_dark_theme =
"redux-color"
259mermaid_init_config = {
260 "theme":
"redux-color",
267htmlhelp_basename =
"3DSlicerdoc"
291 (master_doc,
"3DSlicer.tex",
"3D Slicer Documentation",
292 "Slicer Community",
"manual"),
301 (master_doc,
"3Dslicer",
"3D Slicer Documentation",
312 (master_doc,
"3DSlicer",
"3D Slicer Documentation",
313 author,
"3DSlicer",
"One line description of project.",
338docsfolder = os.path.dirname(__file__)
342 os.path.join(docsfolder,
"../Modules/CLI"),
343 os.path.join(docsfolder,
"_extracli"),
350 "TestGridTransformRegistration.xml",
351 "DiffusionTensorTest.xml",
355outpath = os.path.join(docsfolder,
"_moduledescriptions")
356os.makedirs(outpath, exist_ok=
True)
357with open(os.path.join(outpath,
"_readme_.txt"),
"w")
as descriptionfile:
358 descriptionfile.write(
"Content of this folder is automatically generated by Docs/conf.py from CLI module descriptor XML files\n")
359 descriptionfile.write(
"during documentation build. The folder can be deleted because it is automatically regenerated when needed.")
362def _generatemd(dom, docsfolder, outpath, xslt, suffix):
363 """Helper function to create markdown file from CLI module description XML file using XSLT"""
364 xsltpath = os.path.join(docsfolder, xslt)
365 transform = ET.XSLT(ET.parse(xsltpath))
366 content = str(transform(dom))
367 with open(os.path.join(outpath, os.path.splitext(name)[0] + suffix +
".md"),
"w", encoding=
"utf8")
as outfile:
368 outfile.write(content)
371for inputpath
in inputpaths:
372 for root, dirs, files
in os.walk(inputpath):
374 if name
in excludenames:
376 if name.endswith(
".xml"):
377 print(f
"Generating CLI module documentation from {name}")
378 dom = ET.parse(os.path.join(root, name))
379 _generatemd(dom, docsfolder, outpath,
"cli_module_overview_to_md.xsl",
"Overview")
380 _generatemd(dom, docsfolder, outpath,
"cli_module_parameters_to_md.xsl",
"Parameters")
385 def _hide_edit_link_on_special_pages(app, pagename, templatename, context, doctree):
386 if pagename
in (
"genindex",
"search"):
387 context[
"display_github"] =
False
388 app.connect(
"html-page-context", _hide_edit_link_on_special_pages)
_get_apidocs_doxygen_version()
_extract_slicer_xy_version(slicer_src_dir)