]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- add new sphinx handlers to render method and attribute inheritance
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Sep 2012 18:39:05 +0000 (14:39 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 9 Sep 2012 18:39:05 +0000 (14:39 -0400)
for inherited members

doc/build/builder/builders.py
doc/build/static/docs.css

index be684f03942a45e99b9d43f2944dfbb2ca54dc98..586eff4580a1c5538baa483f5fe2f53f22561db8 100644 (file)
@@ -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
 
index 33f715af11b3676dc9415f9ae0777c43c382df5d..b8e334616ba088f8d3433193478438f03e8455f6 100644 (file)
@@ -7,7 +7,7 @@ body {
 }
 
 a {
-    font-weight:normal; 
+    font-weight:normal;
     text-decoration:none;
 }
 
@@ -29,7 +29,7 @@ a:hover {
 
 /* paragraph links after sections.
    These aren't visible until hovering
-   over the <h> tag, then have a 
+   over the <h> tag, then have a
    "reverse video" effect over the actual
    link
  */
@@ -252,7 +252,7 @@ a.headerlink:hover {
 }
 
 #docs-container pre {
-  background-color: #f0f0f0;  
+  background-color: #f0f0f0;
   border: solid 1px #ccc;
   box-shadow: 2px 2px 3px #DFDFDF;
   padding:10px;
@@ -284,7 +284,7 @@ a.headerlink:hover {
   line-height:1.2em;
 }
 
-#docs-container a.sql_link, 
+#docs-container a.sql_link,
 #docs-container .sql_link
 {
     text-decoration: none;
@@ -316,6 +316,13 @@ div.admonition, div.topic, p.deprecated, p.versionadded, p.versionchanged {
     box-shadow: 2px 2px 3px #DFDFDF;
 }
 
+div.inherited-member {
+    border:1px solid #CCCCCC;
+    padding:5px 5px;
+    font-size:.9em;
+    box-shadow: 2px 2px 3px #DFDFDF;
+}
+
 p.versionadded span.versionmodified,
 p.versionchanged span.versionmodified,
 p.deprecated span.versionmodified {
@@ -349,6 +356,7 @@ dl.exception > dt
 }
 
 
+
 dt:target, span.highlight {
     background-color:#FBE54E;
 }
@@ -400,7 +408,7 @@ tt {
 .go {color:#804049;}
 
 
-/* special "index page" sections 
+/* special "index page" sections
    with specific formatting
 */