Debian Codegraph @

docs/conf.py

raw
1 extensions = [
2 "sphinx.ext.todo",
3 "sphinx.ext.intersphinx",
4 "sphinx.ext.extlinks",
5 "sphinx_copybutton",
6 ]
7
8 import re
9 import shutil
10 from pathlib import Path
11
12
13 def post_process_build(app, exception):
14 """Flatten static files and fix HTML paths for subdirectories."""
15 if exception:
16 return
17
18 static = Path(app.outdir) / "_static"
19 # Flatten images directory
20 if (img := static / "images").exists():
21 for f in img.iterdir():
22 if f.is_file():
23 shutil.move(str(f), str(static / f.name))
24 img.rmdir()
25
26 # Fix _static/ paths in HTML
27 for html in Path(app.outdir).rglob("*.html"):
28 depth = len(html.relative_to(app.outdir).parts) - 1
29 prefix = "../" * depth + "_static/" if depth else "_static/"
30 content = html.read_text(encoding="utf-8")
31 if (new := re.sub(r'src="_static/', f'src="{prefix}', content)) != content:
32 html.write_text(new, encoding="utf-8")
33
34
35 def setup(app):
36 app.connect("build-finished", post_process_build)
37
38
39 intersphinx_mapping = {
40 "python": ("https://docs.python.org/3", None),
41 "cairo": ("https://pycairo.readthedocs.io/en/latest", None),
42 "apidocs": (
43 "https://api.pygobject.gnome.org/",
44 None,
45 ),
46 }
47
48 source_suffix = {".rst": "restructuredtext"}
49 templates_path = ["_templates"]
50 master_doc = "index"
51 exclude_patterns = ["_build", "README.rst"]
52
53 pygments_style = "tango"
54 html_theme = "pydata_sphinx_theme"
55 html_show_copyright = False
56 html_favicon = "images/favicon.ico"
57 project = "PyGObject"
58 html_title = project
59
60 html_context = {
61 "display_gitlab": True,
62 "gitlab_user": "GNOME",
63 "gitlab_repo": "pygobject",
64 "gitlab_version": "main",
65 "conf_py_path": "/docs/",
66 "gitlab_host": "gitlab.gnome.org",
67 }
68
69 html_static_path = ["images", "."]
70 html_css_files = ["extra.css"]
71
72 extlinks = {
73 "bzbug": ("https://bugzilla.gnome.org/show_bug.cgi?id=%s", "bz#%s"),
74 "issue": ("https://gitlab.gnome.org/GNOME/pygobject/-/issues/%s", "#%s"),
75 "commit": ("https://gitlab.gnome.org/GNOME/pygobject/commit/%s", "%s"),
76 "mr": ("https://gitlab.gnome.org/GNOME/pygobject/-/merge_requests/%s", "!%s"),
77 "user": ("https://gitlab.gnome.org/%s", "%s"),
78 "devdocs": ("https://developer.gnome.org/documentation/%s.html", None),
79 }
80
81 suppress_warnings = ["image.nonlocal_uri"]