Debian Codegraph @

doc/conf.py

raw
1 # COLMAP documentation build configuration file, created by
2 # sphinx-quickstart on Wed Jan 28 09:31:25 2015.
3 #
4 # This file is execfile()d with the current directory set to its
5 # containing dir.
6 #
7 # Note that not all possible configuration values are present in this
8 # autogenerated file.
9 #
10 # All configuration values have a default; values that are commented out
11 # serve to show the default.
12
13 import re
14 import subprocess
15
16 from sphinx.ext import autodoc
17
18
19 def get_git_revision():
20 try:
21 commit_id = (
22 subprocess.check_output(["git", "rev-parse", "--short", "HEAD"])
23 .decode()
24 .strip()
25 )
26 commit_date = (
27 subprocess.check_output(
28 ["git", "log", "-1", "--format=%cd", "--date=short"]
29 )
30 .decode()
31 .strip()
32 )
33 return f"{commit_id} ({commit_date})"
34 except Exception:
35 return "Unknown"
36
37
38 # If extensions (or modules to document with autodoc) are in another directory,
39 # add these directories to sys.path here. If the directory is relative to the
40 # documentation root, use os.path.abspath to make it absolute, like shown here.
41 # sys.path.insert(0, os.path.abspath('.'))
42
43 # -- General configuration ------------------------------------------------
44
45 # If your documentation needs a minimal Sphinx version, state it here.
46 # needs_sphinx = '1.0'
47
48 # Add any Sphinx extension module names here, as strings. They can be
49 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
50 # ones.
51 extensions = [
52 "sphinx.ext.mathjax",
53 "sphinx.ext.autodoc",
54 "sphinx_design",
55 "sphinx_sitemap",
56 "sphinxext.opengraph",
57 ]
58
59 # Add any paths that contain templates here, relative to this directory.
60 templates_path = ["_templates"]
61
62 # The suffix of source filenames.
63 source_suffix = ".rst"
64
65 # The encoding of source files.
66 # source_encoding = 'utf-8-sig'
67
68 # The master toctree document.
69 master_doc = "index"
70
71 # General information about the project.
72 project = "COLMAP"
73 copyright = "2026, COLMAP Team"
74
75 # The version info for the project you're documenting, acts as replacement for
76 # |version| and |release|, also used in various other places throughout the
77 # built documents.
78 #
79 # The short MAJOR.MINOR.PATCH version.
80 version = "4.2.0" + " | " + get_git_revision()
81 # The full version, including alpha/beta/rc tags.
82 release = version
83
84 # The language for content autogenerated by Sphinx. Refer to documentation
85 # for a list of supported languages.
86 # language = None
87
88 # There are two options for replacing |today|: either, you set today to some
89 # non-false value, then it is used:
90 # today = ''
91 # Else, today_fmt is used as the format for a strftime call.
92 # today_fmt = '%B %d, %Y'
93
94 # List of patterns, relative to source directory, that match files and
95 # directories to ignore when looking for source files.
96 exclude_patterns = ["_build"]
97
98 # The reST default role (used for this markup: `text`) to use for all
99 # documents.
100 # default_role = None
101
102 # If true, '()' will be appended to :func: etc. cross-reference text.
103 # add_function_parentheses = True
104
105 # If true, the current module name will be prepended to all description
106 # unit titles (such as .. function::).
107 # add_module_names = True
108
109 # If true, sectionauthor and moduleauthor directives will be shown in the
110 # output. They are ignored by default.
111 # show_authors = False
112
113 # The name of the Pygments (syntax highlighting) style to use.
114 pygments_style = "sphinx"
115
116 # A list of ignored prefixes for module index sorting.
117 # modindex_common_prefix = []
118
119 # If true, keep warnings as "system message" paragraphs in the built documents.
120 # keep_warnings = False
121
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 html_theme = "pydata_sphinx_theme"
128
129 # Theme options are theme-specific and customize the look and feel of a theme
130 # further. For a list of options available for each theme, see the
131 # documentation.
132 html_theme_options = {
133 "logo": {
134 "text": "COLMAP",
135 "image_light": "_static/colmap-logo.svg",
136 "image_dark": "_static/colmap-logo-dark.svg",
137 },
138 "icon_links": [
139 {
140 "name": "GitHub",
141 "url": "https://github.com/colmap/colmap",
142 "icon": "fa-brands fa-github",
143 },
144 {
145 "name": "PyPI",
146 "url": "https://pypi.org/project/pycolmap/",
147 "icon": "fa-brands fa-python",
148 },
149 {
150 "name": "Docker Hub",
151 "url": "https://hub.docker.com/r/colmap/colmap",
152 "icon": "fa-brands fa-docker",
153 },
154 ],
155 "navbar_align": "left",
156 # Keep the primary guides and 3D Viewer visible. Collapse the rest into
157 # More.
158 "header_links_before_dropdown": 4,
159 "navigation_with_keys": True,
160 "show_prev_next": True,
161 "pygments_light_style": "default",
162 "pygments_dark_style": "monokai",
163 "footer_start": ["copyright"],
164 "footer_center": ["version"],
165 "footer_end": ["theme-version"],
166 }
167
168 # Follow the visitor's OS/browser preference for light/dark mode by default.
169 html_context = {"default_mode": "auto"}
170
171 # -- SEO -----------------------------------------------------------------
172
173 # Canonical site URL. Base URL for the sitemap and Open Graph tags, and makes
174 # every page emit a self-referential <link rel="canonical">. (This alone does
175 # not dedupe the hosted legacy/<version>/ copies; those would each need their
176 # own HTML updated to point here.)
177 html_baseurl = "https://colmap.github.io/"
178
179 # sphinx-sitemap: the docs are not multi-version/multi-language, so emit plain
180 # page URLs (no {version}/{lang} path segments).
181 sitemap_url_scheme = "{link}"
182
183 # sphinxext-opengraph: Open Graph / Twitter card metadata + meta description.
184 ogp_site_url = html_baseurl
185 ogp_site_name = "COLMAP"
186 ogp_description_length = 200
187 ogp_enable_meta_description = True
188 ogp_image = "https://colmap.github.io/_static/og-image.png"
189 ogp_image_alt = "COLMAP — Structure-from-Motion & Multi-View Stereo"
190 ogp_use_first_image = False
191 ogp_custom_meta_tags = [
192 '<meta name="twitter:card" content="summary_large_image" />',
193 ]
194
195 # Copy robots.txt (which points crawlers to the sitemap) to the site root.
196 html_extra_path = ["robots.txt"]
197
198 # The name for this set of Sphinx documents. If None, it defaults to
199 # "<project> v<release> documentation".
200 html_title = "COLMAP"
201
202 # A shorter title for the navigation bar. Default is the same as html_title.
203 # html_short_title = None
204
205 # The name of an image file (relative to this directory) to place at the top
206 # of the sidebar.
207 html_logo = "_static/colmap-logo.svg"
208
209 # The name of an image file (within the static path) to use as favicon of the
210 # docs.
211 html_favicon = "_static/favicon.svg"
212
213 # Give the landing page a full-width layout by dropping the left sidebar.
214 html_sidebars = {"index": [], "viewer": []}
215
216 # Add any paths that contain custom static files (such as style sheets) here,
217 # relative to this directory. They are copied after the builtin static files,
218 # so a file named "default.css" will overwrite the builtin "default.css".
219 html_static_path = ["_static"]
220 html_css_files = ["custom.css", "landing.css"]
221 html_js_files = ["install_selector.js", "external_links.js"]
222
223 # Add any extra paths that contain custom files (such as robots.txt or
224 # .htaccess) here, relative to this directory. These files are copied
225 # directly to the root of the documentation.
226 # html_extra_path = []
227
228 # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
229 # using the given strftime format.
230 # html_last_updated_fmt = '%b %d, %Y'
231
232 # If true, SmartyPants will be used to convert quotes and dashes to
233 # typographically correct entities.
234 # html_use_smartypants = True
235
236 # Custom sidebar templates, maps document names to template names.
237 # html_sidebars = {}
238
239 # Additional templates that should be rendered to pages, maps page names to
240 # template names.
241 # html_additional_pages = {}
242
243 # If false, no module index is generated.
244 # html_domain_indices = True
245
246 # If false, no index is generated.
247 # html_use_index = True
248
249 # If true, the index is split into individual pages for each letter.
250 # html_split_index = False
251
252 # If true, links to the reST sources are added to the pages.
253 # html_show_sourcelink = True
254
255 # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
256 # html_show_sphinx = True
257
258 # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
259 # html_show_copyright = True
260
261 # If true, an OpenSearch description file will be output, and all pages will
262 # contain a <link> tag referring to it. The value of this option must be the
263 # base URL from which the finished HTML is served.
264 # html_use_opensearch = ''
265
266 # This is the file name suffix for HTML files (e.g. ".xhtml").
267 # html_file_suffix = None
268
269 # Output file base name for HTML help builder.
270 htmlhelp_basename = "COLMAPdoc"
271
272
273 # -- Options for LaTeX output ---------------------------------------------
274
275 latex_elements = {
276 # The paper size ('letterpaper' or 'a4paper').
277 # 'papersize': 'a4paper',
278 # The font size ('10pt', '11pt' or '12pt').
279 # 'pointsize': '10pt',
280 # Additional stuff for the LaTeX preamble.
281 # 'preamble': '',
282 }
283
284 # Grouping the document tree into LaTeX files. List of tuples
285 # (source start file, target name, title,
286 # author, documentclass [howto, manual, or own class]).
287 latex_documents = [
288 (
289 "index",
290 "COLMAP.tex",
291 "COLMAP Documentation",
292 "Johannes L. Schoenberger",
293 "manual",
294 ),
295 ]
296
297 # The name of an image file (relative to this directory) to place at the top of
298 # the title page.
299 # latex_logo = None
300
301 # For "manual" documents, if this is true, then toplevel headings are parts,
302 # not chapters.
303 # latex_use_parts = False
304
305 # If true, show page references after internal links.
306 latex_show_pagerefs = True
307
308 # If true, show URL addresses after external links.
309 latex_show_urls = "footnote"
310
311 # Documents to append as an appendix to all manuals.
312 # latex_appendices = []
313
314 # If false, no module index is generated.
315 latex_domain_indices = False
316
317
318 # -- Options for manual page output ---------------------------------------
319
320 # One entry per manual page. List of tuples
321 # (source start file, name, description, authors, manual section).
322 man_pages = [
323 (
324 "index",
325 "colmap",
326 "COLMAP Documentation",
327 ["Johannes L. Schoenberger"],
328 1,
329 )
330 ]
331
332 # If true, show URL addresses after external links.
333 # man_show_urls = False
334
335
336 # -- Options for Texinfo output -------------------------------------------
337
338 # Grouping the document tree into Texinfo files. List of tuples
339 # (source start file, target name, title, author,
340 # dir menu entry, description, category)
341 texinfo_documents = [
342 (
343 "index",
344 "COLMAP",
345 "COLMAP Documentation",
346 "Johannes L. Schoenberger",
347 "COLMAP",
348 "Structure-from-Motion and Multi-View Stereo.",
349 "Miscellaneous",
350 ),
351 ]
352
353 # Documents to append as an appendix to all manuals.
354 # texinfo_appendices = []
355
356 # If false, no module index is generated.
357 # texinfo_domain_indices = True
358
359 # How to display URL addresses: 'footnote', 'no', or 'inline'.
360 # texinfo_show_urls = 'footnote'
361
362 # If true, do not generate a @detailmenu in the "Top" node's menu.
363 # texinfo_no_detailmenu = False
364
365 # Configure how Python API docs are displayed.
366 autoclass_content = "both"
367 autodoc_member_order = "bysource"
368 autodoc_typehints = "both"
369 python_maximum_signature_line_length = 120
370 autodoc_use_legacy_class_based = True
371
372
373 def sort_members(
374 self, documenters: list[tuple[autodoc.Documenter, bool]], order: str
375 ) -> list[tuple[autodoc.Documenter, bool]]:
376 """Order the members by their definition order."""
377 class_names = list(self.object.__dict__)
378
379 def keyfunc(entry: tuple[autodoc.Documenter, bool]) -> int:
380 name = entry[0].name.split("::")[1].split(".")[1]
381 if name in class_names:
382 return class_names.index(name)
383 else:
384 return len(class_names)
385
386 documenters.sort(key=keyfunc)
387 return documenters
388
389
390 # autodoc_member_order=bysource does not work for C++-defined classes since they
391 # cannot be introspected and do not have an __all__ list. Instead,
392 # we extract the definition order from object.__dict__.
393 autodoc.ClassDocumenter.sort_members = sort_members
394
395
396 def process_doc(app, what, name, obj, options, lines):
397 if not lines:
398 return
399 has_overload = lines[0] == "Overloaded function."
400 for i in range(len(lines)):
401 lines[i] = lines[i].replace("pycolmap._core", "pycolmap")
402 if has_overload and re.search(r"^\d+\. ", lines[i]):
403 index, signature = lines[i].split(". ", 1)
404 signature = "``" + signature.replace("->", "→") + "``"
405 lines[i] = ". ".join([index, signature])
406
407
408 def process_sig(app, what, name, obj, options, signature, return_annotation):
409 if signature is None:
410 return None, return_annotation
411 signature = signature.replace("pycolmap._core", "pycolmap")
412 if isinstance(return_annotation, str):
413 return_annotation = return_annotation.replace(
414 "pycolmap._core", "pycolmap"
415 )
416 return signature, return_annotation
417
418
419 def setup(app):
420 # Remap types from the C++ module pycolmap._core to the Python namespace.
421 app.connect("autodoc-process-docstring", process_doc)
422 app.connect("autodoc-process-signature", process_sig)