diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-09 14:39:05 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-09-09 14:39:05 -0400 |
commit | b96250d0063cd7ce9cc1f95abade68e6656d6acb (patch) | |
tree | 74d44bfe83ab92ce098c561db9130d63d5d9d55c /doc/build/builder | |
parent | a10ea71125e0f873683831bfc736edfd8a5a8b1a (diff) | |
download | sqlalchemy-b96250d0063cd7ce9cc1f95abade68e6656d6acb.tar.gz |
- add new sphinx handlers to render method and attribute inheritance
for inherited members
Diffstat (limited to 'doc/build/builder')
-rw-r--r-- | doc/build/builder/builders.py | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/doc/build/builder/builders.py b/doc/build/builder/builders.py index be684f039..586eff458 100644 --- a/doc/build/builder/builders.py +++ b/doc/build/builder/builders.py @@ -193,11 +193,44 @@ class PopupLatexFormatter(LatexFormatter): LatexFormatter.format(self, self._filter_tokens(tokensource), outfile) def autodoc_skip_member(app, what, name, obj, skip, options): - if what == 'class' and skip and name in ('__init__', '__eq__', '__ne__', '__lt__', '__le__') and obj.__doc__: + if what == 'class' and skip and \ + name in ('__init__', '__eq__', '__ne__', '__lt__', '__le__') and \ + obj.__doc__: return False else: return skip +# im sure this is in the app somewhere, but I don't really +# know where, so we're doing it here. +_track_autodoced = {} +def autodoc_process_docstring(app, what, name, obj, options, lines): + if what == "class": + _track_autodoced[name] = obj + elif what in ("attribute", "method") and \ + options.get("inherited-members"): + m = re.match(r'(.*?)\.([\w_]+)$', name) + if m: + clsname, attrname = m.group(1, 2) + if clsname in _track_autodoced: + cls = _track_autodoced[clsname] + for supercls in cls.__mro__: + if attrname in supercls.__dict__: + break + if supercls is not cls: + lines[:0] = [ + ".. container:: inherited_member", + "", + " *inherited from the* :%s:`.%s.%s` *%s of* :class:`.%s`" % ( + "attr" if what == "attribute" + else "meth", + supercls.__name__, + attrname, + what, + supercls.__name__ + ), + "" + ] + def setup(app): app.add_lexer('pycon+sql', PyConWithSQLLexer()) app.add_lexer('python+sql', PythonWithSQLLexer()) @@ -205,6 +238,7 @@ def setup(app): app.add_config_value('site_base', "", True) app.add_config_value('build_number', "", 1) app.connect('autodoc-skip-member', autodoc_skip_member) + app.connect('autodoc-process-docstring', autodoc_process_docstring) PygmentsBridge.html_formatter = PopupSQLFormatter PygmentsBridge.latex_formatter = PopupLatexFormatter |