Skip to content

Commit cebd994

Browse files
asumagicpplantinga
authored andcommitted
Mock some dependencies for docs
1 parent c852615 commit cebd994

File tree

2 files changed

+51
-22
lines changed

2 files changed

+51
-22
lines changed

docs/conf.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import os
1414
import sys
1515

16+
import better_apidoc
1617
import hyperpyyaml
18+
from sphinx.ext.autodoc.mock import mock
1719

1820
sys.path.insert(-1, os.path.abspath("../"))
1921

@@ -69,8 +71,19 @@
6971

7072
autodoc_default_options = {}
7173

72-
# Autodoc mock extra dependencies:
73-
autodoc_mock_imports = []
74+
# Autodoc mock extra dependencies -- doesn't work out of the box, because of better_apidoc.
75+
#
76+
# So, let's reuse the autodoc mock...
77+
#
78+
# We would also like to mock more imports than this but this is shockingly prone
79+
# to randomly breaking, so let's keep a small-ish set of dependencies that tend
80+
# to be more annoying to install and to nuke our CI on update
81+
autodoc_mock_imports = [
82+
"k2",
83+
"flair",
84+
"fairseq",
85+
"spacy",
86+
]
7487

7588
# Order of API items:
7689
autodoc_member_order = "bysource"
@@ -95,23 +108,42 @@
95108

96109
def run_apidoc(app):
97110
"""Generate API documentation"""
98-
import better_apidoc
99-
100-
better_apidoc.APP = app
101-
better_apidoc.main(
102-
[
103-
"better-apidoc",
104-
"-t",
105-
"_apidoc_templates",
106-
"--force",
107-
"--no-toc",
108-
"--separate",
109-
"-o",
110-
"API",
111-
os.path.join("../", "speechbrain"),
112-
os.path.dirname(hyperpyyaml.__file__),
113-
]
114-
)
111+
112+
with mock(autodoc_mock_imports):
113+
try:
114+
better_apidoc.APP = app
115+
better_apidoc.main(
116+
[
117+
"better-apidoc",
118+
"-t",
119+
"_apidoc_templates",
120+
"--force",
121+
"--no-toc",
122+
"--separate",
123+
"-o",
124+
"API",
125+
os.path.join("../", "speechbrain"),
126+
]
127+
)
128+
better_apidoc.main(
129+
[
130+
"better-apidoc",
131+
"-t",
132+
"_apidoc_templates",
133+
"--force",
134+
"--no-toc",
135+
"--separate",
136+
"-o",
137+
"API",
138+
os.path.dirname(hyperpyyaml.__file__),
139+
]
140+
)
141+
except Exception:
142+
# because otherwise sphinx very helpfully eats the backtrace
143+
import traceback
144+
145+
print(traceback.format_exc(), file=sys.stderr)
146+
raise
115147

116148

117149
# -- Options for HTML output -------------------------------------------------

docs/docs-requirements.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
better-apidoc>=0.3.1
22
ctc-segmentation>=1.7.0
3-
fairseq @ git+https://github.com/facebookresearch/fairseq.git@v0.12.3
4-
flair==0.13.1
53
https://github.com/kpu/kenlm/archive/master.zip
64
numba>=0.54.1
75
pyctcdecode
86
recommonmark>=0.7.1
97
scikit-learn
108
six
11-
spacy==3.7.4
129
sphinx-rtd-theme>=0.4.3
1310
Sphinx>=3.4.3
1411
transformers

0 commit comments

Comments
 (0)