2828import sphinx
2929from sphinx .addnodes import pending_xref , desc_content
3030from sphinx .util import logging
31+ from sphinx .errors import ExtensionError
3132
3233if sphinx .__version__ < '1.6.5' :
3334 raise RuntimeError ("Sphinx 1.6.5 or newer is required" )
@@ -231,7 +232,13 @@ def setup(app, get_doc_object_=get_doc_object):
231232
232233 app .setup_extension ('sphinx.ext.autosummary' )
233234
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+
235242 app .connect ('autodoc-process-docstring' , mangle_docstrings )
236243 app .connect ('autodoc-process-signature' , mangle_signature )
237244 app .connect ('doctree-read' , relabel_references )
@@ -257,17 +264,19 @@ def setup(app, get_doc_object_=get_doc_object):
257264 return metadata
258265
259266
260- def update_config (app ):
267+ def update_config (app , config = None ):
261268 """Update the configuration with default values."""
269+ if config is None : # needed for testing and old Sphinx
270+ config = app .config
262271 # Do not simply overwrite the `app.config.numpydoc_xref_aliases`
263272 # otherwise the next sphinx-build will compare the incoming values (without
264273 # our additions) to the old values (with our additions) and trigger
265274 # a full rebuild!
266- numpydoc_xref_aliases_complete = deepcopy (app . config .numpydoc_xref_aliases )
275+ numpydoc_xref_aliases_complete = deepcopy (config .numpydoc_xref_aliases )
267276 for key , value in DEFAULT_LINKS .items ():
268277 if key not in numpydoc_xref_aliases_complete :
269278 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
271280
272281
273282# ------------------------------------------------------------------------------
0 commit comments