28
28
import sphinx
29
29
from sphinx .addnodes import pending_xref , desc_content
30
30
from sphinx .util import logging
31
+ from sphinx .errors import ExtensionError
31
32
32
33
if sphinx .__version__ < '1.6.5' :
33
34
raise RuntimeError ("Sphinx 1.6.5 or newer is required" )
@@ -231,7 +232,13 @@ def setup(app, get_doc_object_=get_doc_object):
231
232
232
233
app .setup_extension ('sphinx.ext.autosummary' )
233
234
234
- app .connect ('builder-inited' , update_config )
235
+ # Once we bump our Sphinx requirement higher (1.7 or 1.8?)
236
+ # we can just connect to config-inited
237
+ try :
238
+ app .connect ('config-inited' , update_config )
239
+ except ExtensionError :
240
+ app .connect ('builder-inited' , update_config )
241
+
235
242
app .connect ('autodoc-process-docstring' , mangle_docstrings )
236
243
app .connect ('autodoc-process-signature' , mangle_signature )
237
244
app .connect ('doctree-read' , relabel_references )
@@ -257,17 +264,19 @@ def setup(app, get_doc_object_=get_doc_object):
257
264
return metadata
258
265
259
266
260
- def update_config (app ):
267
+ def update_config (app , config = None ):
261
268
"""Update the configuration with default values."""
269
+ if config is None : # needed for testing and old Sphinx
270
+ config = app .config
262
271
# Do not simply overwrite the `app.config.numpydoc_xref_aliases`
263
272
# otherwise the next sphinx-build will compare the incoming values (without
264
273
# our additions) to the old values (with our additions) and trigger
265
274
# a full rebuild!
266
- numpydoc_xref_aliases_complete = deepcopy (app . config .numpydoc_xref_aliases )
275
+ numpydoc_xref_aliases_complete = deepcopy (config .numpydoc_xref_aliases )
267
276
for key , value in DEFAULT_LINKS .items ():
268
277
if key not in numpydoc_xref_aliases_complete :
269
278
numpydoc_xref_aliases_complete [key ] = value
270
- app . config .numpydoc_xref_aliases_complete = numpydoc_xref_aliases_complete
279
+ config .numpydoc_xref_aliases_complete = numpydoc_xref_aliases_complete
271
280
272
281
273
282
# ------------------------------------------------------------------------------
0 commit comments