6363from collections import defaultdict
6464from six import string_types
6565
66+ import sphinx
6667from sphinx .ext import autodoc
6768from sphinx .util .console import bold , darkgreen , green , red
6869
@@ -126,7 +127,7 @@ def find_python_modules(package):
126127 abs = os .path .abspath (current_dist )
127128 dist_name = os .path .basename (abs )
128129
129- for dirpath , dirnames , filenames in os .walk (abs ):
130+ for dirpath , _ , filenames in os .walk (abs ):
130131 package = (dist_name + dirpath [len (abs ):]).replace ('/' , '.' )
131132 if '__init__.py' in filenames :
132133 yield package
@@ -218,6 +219,24 @@ def as_dict(self):
218219 }
219220
220221
222+ def _add_documenter_override (app , cls ):
223+ # Install documenter for automodule without generating warning.
224+ from sphinx .ext .autodoc .directive import AutodocDirective
225+ app .registry .add_documenter (cls .objtype , cls )
226+ directive_name = 'auto' + cls .objtype
227+ if sphinx .version_info < (1 , 8 ):
228+ try :
229+ from docutils .parsers .rst import directives
230+ except ImportError :
231+ pass
232+ else :
233+ directives ._directives .pop (directive_name , None )
234+ app .add_directive (directive_name , AutodocDirective )
235+ else :
236+ # override was added in Sphinx 1.8
237+ app .add_directive (directive_name , AutodocDirective , override = True )
238+
239+
221240def setup (app ):
222241 app .add_builder (APICheckBuilder )
223242 app .add_config_value (
@@ -226,8 +245,8 @@ def setup(app):
226245 bytes_if_py2 ('apicheck_domains' ), ['py' ], False )
227246 app .add_config_value (
228247 bytes_if_py2 ('apicheck_package' ), None , False )
229- app . add_autodocumenter ( ModuleDocumenter )
248+ _add_documenter_override ( app , ModuleDocumenter )
230249
231250 return {
232- 'parallel_read_safe' : True
251+ 'parallel_read_safe' : True ,
233252 }
0 commit comments