Skip to content

Commit a8c9d73

Browse files
committed
[no ci] docs: move autodoc docstring adaptations to separate file
1 parent ade323f commit a8c9d73

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

docsrc/pre-build.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def patch_conf(sourcedir):
6666
"_static/bayesflow_hor.png",
6767
"_static/custom.css",
6868
"sphinxext/override_pst_pagetoc.py",
69+
"sphinxext/adapt_autodoc_docstring.py",
6970
]
7071
for path in copy_rel_paths:
7172
srcfile = cursrc / path

docsrc/source/conf.py

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
"sphinx.ext.intersphinx",
5757
"sphinx_design",
5858
"sphinxcontrib.bibtex",
59-
"override_pst_pagetoc",
59+
"override_pst_pagetoc", # local, see sphinxext folder
60+
"adapt_autodoc_docstring", # local, see sphinxext folder
6061
]
6162

6263
intersphinx_mapping = {
@@ -167,36 +168,3 @@
167168
current: GitRef = data["current"]
168169
except LoadError:
169170
print("sphinx_polyversion could not load. Building single version")
170-
171-
172-
def docstring(app, what, name, obj, options, lines):
173-
"""Adapt autodoc docstring.
174-
175-
Inherited Keras docstrings do not follow the numpy docstring format.
176-
Most noticably, they use Markdown code fences. To improve the situation
177-
somewhat, this functions aims to convert fenced code blocks to RST
178-
code blocks.
179-
"""
180-
updated_lines = []
181-
prefix = ""
182-
for line in lines:
183-
if line.count("```") == 1:
184-
if prefix == "":
185-
prefix = " "
186-
updated_lines[-1] = updated_lines[-1] + "::"
187-
else:
188-
prefix = ""
189-
updated_lines.append("\n")
190-
else:
191-
updated_lines.append(prefix + line)
192-
if prefix != "":
193-
raise ValueError(
194-
f"Uneven number of code fences in docstring:\nwhat='{what}', name='{name}'.\n" + "\n".join(lines)
195-
)
196-
# overwrite lines list
197-
lines.clear()
198-
lines += updated_lines
199-
200-
201-
def setup(app):
202-
app.connect("autodoc-process-docstring", docstring)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
def docstring(app, what, name, obj, options, lines):
2+
"""Adapt autodoc docstring.
3+
4+
Inherited Keras docstrings do not follow the numpy docstring format.
5+
Most noticably, they use Markdown code fences. To improve the situation
6+
somewhat, this functions aims to convert fenced code blocks to RST
7+
code blocks.
8+
"""
9+
updated_lines = []
10+
prefix = ""
11+
for line in lines:
12+
if line.count("```") == 1:
13+
if prefix == "":
14+
prefix = " "
15+
updated_lines[-1] = updated_lines[-1] + "::"
16+
else:
17+
prefix = ""
18+
updated_lines.append("\n")
19+
else:
20+
updated_lines.append(prefix + line)
21+
if prefix != "":
22+
raise ValueError(
23+
f"Uneven number of code fences in docstring:\nwhat='{what}', name='{name}'.\n" + "\n".join(lines)
24+
)
25+
# overwrite lines list
26+
lines.clear()
27+
lines += updated_lines
28+
29+
30+
def setup(app):
31+
app.connect("autodoc-process-docstring", docstring)

0 commit comments

Comments
 (0)