diff --git a/doc/sources/conf.py b/doc/sources/conf.py index a70d7c8dd..b060b1da8 100644 --- a/doc/sources/conf.py +++ b/doc/sources/conf.py @@ -23,7 +23,7 @@ sys.path.append(os.path.abspath('sphinxext')) # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. -extensions = ['sphinx.ext.autodoc', 'sphinx.ext.todo', 'preprocess'] +extensions = ['autodoc', 'sphinx.ext.todo', 'preprocess'] # Todo configuration todo_include_todos = True diff --git a/doc/sources/sphinxext/autodoc.py b/doc/sources/sphinxext/autodoc.py new file mode 100644 index 000000000..ecca06f9e --- /dev/null +++ b/doc/sources/sphinxext/autodoc.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from sphinx.ext.autodoc import Documenter, ClassDocumenter +from sphinx.ext.autodoc import setup as core_setup +from sphinx.locale import _ + + +class KivyClassDocumenter(ClassDocumenter): + def add_directive_header(self, sig): + if self.doc_as_attr: + self.directivetype = 'attribute' + Documenter.add_directive_header(self, sig) + + def fix(mod): + if mod == 'kivy._event': + mod = 'kivy.event' + return mod + + # add inheritance info, if wanted + if not self.doc_as_attr and self.options.show_inheritance: + self.add_line(u'', '') + if len(self.object.__bases__): + bases = [b.__module__ == '__builtin__' and + u':class:`%s`' % b.__name__ or + u':class:`%s.%s`' % (fix(b.__module__), b.__name__) + for b in self.object.__bases__] + self.add_line(_(u' Bases: %s') % ', '.join(bases), + '') +def setup(app): + core_setup(app) + app.add_autodocumenter(KivyClassDocumenter)