| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
import os |
| 9 |
import re |
| 10 |
import subprocess |
| 11 |
import sys |
| 12 |
from pathlib import Path |
| 13 |
|
| 14 |
project = "libgpiod" |
| 15 |
copyright = "2017-2025, Bartosz Golaszewski" |
| 16 |
author = "Bartosz Golaszewski" |
| 17 |
|
| 18 |
master_doc = "index" |
| 19 |
source_suffix = ".rst" |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
with open("../configure.ac", "r") as fd: |
| 24 |
version = "" |
| 25 |
extra = "" |
| 26 |
for line in fd.readlines(): |
| 27 |
match = re.search(r"AC_INIT\(\[libgpiod\], \[(.*?)\]\)", line) |
| 28 |
if match: |
| 29 |
version = match.group(1) |
| 30 |
continue |
| 31 |
|
| 32 |
match = re.search(r"AC_SUBST\(EXTRA_VERSION, \[(.*?)\]\)", line) |
| 33 |
if match: |
| 34 |
extra = match.group(1) |
| 35 |
|
| 36 |
release = f"{version}{extra}" |
| 37 |
|
| 38 |
extensions = ["breathe", "sphinx.ext.autodoc"] |
| 39 |
|
| 40 |
breathe_projects = {"libgpiod": "./doxygen-output/xml"} |
| 41 |
breathe_default_project = "libgpiod" |
| 42 |
|
| 43 |
sys.path.insert(0, str(Path("../bindings/python").resolve())) |
| 44 |
autodoc_mock_imports = ["gpiod._ext"] |
| 45 |
|
| 46 |
|
| 47 |
sphinx_rtd_theme = None |
| 48 |
try: |
| 49 |
import sphinx_rtd_theme |
| 50 |
|
| 51 |
extensions.append("sphinx_rtd_theme") |
| 52 |
except ImportError: |
| 53 |
pass |
| 54 |
|
| 55 |
html_theme = "sphinx_rtd_theme" if sphinx_rtd_theme else "default" |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
def make_glib_docs(app): |
| 61 |
|
| 62 |
|
| 63 |
prefix = "../" if os.getenv("READTHEDOCS") == "True" else "" |
| 64 |
|
| 65 |
subprocess.run( |
| 66 |
[ |
| 67 |
"gi-docgen", |
| 68 |
"generate", |
| 69 |
"--config", |
| 70 |
f"{prefix}bindings/glib/gi-docgen.toml", |
| 71 |
f"{prefix}bindings/glib/Gpiodglib-1.0.gir", |
| 72 |
"--output-dir", |
| 73 |
f"{app.outdir}", |
| 74 |
], |
| 75 |
check=True, |
| 76 |
) |
| 77 |
|
| 78 |
|
| 79 |
def setup(app): |
| 80 |
app.connect("builder-inited", make_glib_docs) |
| 81 |
|
| 82 |
|
| 83 |
subprocess.run(["doxygen", "Doxyfile"]) |
| 84 |
|
| 85 |
cwd = os.getcwd() |
| 86 |
os.chdir("..") |
| 87 |
subprocess.run(["autoreconf", "-ifv"], check=True) |
| 88 |
subprocess.run( |
| 89 |
[ |
| 90 |
"./configure", |
| 91 |
"--enable-tools", |
| 92 |
"--enable-bindings-glib", |
| 93 |
"--enable-introspection", |
| 94 |
"--enable-tools", |
| 95 |
"--enable-dbus", |
| 96 |
], |
| 97 |
check=True, |
| 98 |
) |
| 99 |
subprocess.run(["make", "-j"], check=True) |
| 100 |
os.chdir(cwd) |
| 101 |
|
| 102 |
for page in [ |
| 103 |
"gpiodetect", |
| 104 |
"gpioinfo", |
| 105 |
"gpioget", |
| 106 |
"gpioset", |
| 107 |
"gpiomon", |
| 108 |
"gpionotify", |
| 109 |
"gpio-manager", |
| 110 |
"gpiocli", |
| 111 |
"gpiocli-detect", |
| 112 |
"gpiocli-find", |
| 113 |
"gpiocli-info", |
| 114 |
"gpiocli-get", |
| 115 |
"gpiocli-monitor", |
| 116 |
"gpiocli-notify", |
| 117 |
"gpiocli-reconfigure", |
| 118 |
"gpiocli-release", |
| 119 |
"gpiocli-request", |
| 120 |
"gpiocli-requests", |
| 121 |
"gpiocli-set", |
| 122 |
"gpiocli-wait", |
| 123 |
]: |
| 124 |
subprocess.run( |
| 125 |
[ |
| 126 |
"pandoc", |
| 127 |
"--from=man", |
| 128 |
"--to=rst", |
| 129 |
"--standalone", |
| 130 |
"--wrap=none", |
| 131 |
f"--output={page}.rst", |
| 132 |
f"../man/{page}.man", |
| 133 |
], |
| 134 |
check=True, |
| 135 |
) |
| 136 |
|
| 137 |
subprocess.run(["gdbus-codegen", "--generate-rst", "dbus", "../dbus/lib/io.gpiod1.xml"]) |