File: import-sphinxconfig.patch

package info (click to toggle)
pyopencl 2025.1-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,152 kB
  • sloc: python: 21,012; cpp: 7,986; lisp: 3,539; ansic: 523; makefile: 44; sh: 37
file content (118 lines) | stat: -rw-r--r-- 3,400 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From: Debian OpenCL Maintainers <pkg-opencl-devel@lists.alioth.debian.org>
Date: Tue, 21 Feb 2023 11:23:15 +0100
Subject: import sphinxconfig.py for offline usage

Forwarded: not needed

the sphinx config was moved by upstream to
https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py
and is retrieved at build time

import it back into the package s.t.
- the package can be built without requiring network access
- the sphinx config can be patched
---
 doc/conf.py         |  3 +-
 doc/sphinxconfig.py | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 doc/sphinxconfig.py

diff --git a/doc/conf.py b/doc/conf.py
index b419a7c..45ea337 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -3,7 +3,8 @@ from urllib.request import urlopen
 
 _conf_url = \
         "https://raw.githubusercontent.com/inducer/sphinxconfig/main/sphinxconfig.py"
-with urlopen(_conf_url) as _inf:
+#with urlopen(_conf_url) as _inf:
+with open("sphinxconfig.py") as _inf:
     exec(compile(_inf.read(), _conf_url, "exec"), globals())
 
 exclude_patterns = ["subst.rst"]
diff --git a/doc/sphinxconfig.py b/doc/sphinxconfig.py
new file mode 100644
index 0000000..e3b69ff
--- /dev/null
+++ b/doc/sphinxconfig.py
@@ -0,0 +1,79 @@
+from os.path import dirname as _dirname, basename as _basename
+
+html_theme = "furo"
+html_show_sourcelink = True
+
+project = _basename(_dirname(_dirname(__file__)))
+
+autoclass_content = "class"
+
+copybutton_prompt_text = r">>> |\.\.\. |\$ |In \[\d*\]: | {2,5}\.\.\.: | {5,8}: "
+copybutton_prompt_is_regexp = True
+
+
+def linkcode_resolve(domain, info, linkcode_url=None):
+    import os
+    import sys
+    import inspect
+
+    if domain != "py" or not info["module"]:
+        return None
+
+    submodname = info["module"]
+    topmodname = submodname.split(".")[0]
+    fullname = info["fullname"]
+
+    topmod = sys.modules.get(topmodname)
+    submod = sys.modules.get(submodname)
+    if submod is None:
+        return None
+
+    obj = submod
+    for part in fullname.split("."):
+        try:
+            obj = getattr(obj, part)
+        except Exception:
+            return None
+
+    try:
+        modpath = os.path.dirname(os.path.dirname(inspect.getsourcefile(topmod)))
+        filepath = os.path.relpath(inspect.getsourcefile(obj), modpath)
+        if filepath is None:
+            return
+    except Exception:
+        return None
+
+    try:
+        source, lineno = inspect.getsourcelines(obj)
+    except OSError:
+        return None
+    else:
+        linestart, linestop = lineno, lineno + len(source) - 1
+
+    if linkcode_url is None:
+        linkcode_url = (
+            f"https://github.com/inducer/{project}/blob/"
+            + "main"
+            + "/{filepath}#L{linestart}-L{linestop}"
+        )
+
+    return linkcode_url.format(
+        filepath=filepath, linestart=linestart, linestop=linestop
+    )
+
+
+extensions = [
+        "sphinx.ext.autodoc",
+        "sphinx.ext.intersphinx",
+        "sphinx.ext.linkcode",
+        "sphinx.ext.doctest",
+        "sphinx.ext.mathjax",
+        "sphinx_copybutton",
+        ]
+
+__all__ = ("html_theme", "html_show_sourcelink",
+        "project", "autoclass_content",
+        "copybutton_prompt_text",
+        "copybutton_prompt_is_regexp",
+        "linkcode_resolve",
+        "extensions")