mirror of https://github.com/kivy/kivy.git
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:
parent
58e48fd27c
commit
5e29474863
|
@ -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
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue