doc: extend autodoc extension to fix/hide/live rename module in doc (hide the _event module to the user, always use event module instead.)

This commit is contained in:
Mathieu Virbel 2012-05-29 03:19:58 +02:00
parent 58e48fd27c
commit 5e29474863
2 changed files with 31 additions and 1 deletions

View File

@ -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

View File

@ -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'', '<autodoc>')
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),
'<autodoc>')
def setup(app):
core_setup(app)
app.add_autodocumenter(KivyClassDocumenter)