[Checkins] SVN: zope.app.apidoc/trunk/ When a module provides an interface or has an __all__ attribute,
Shane Hathaway
shane at hathawaymix.org
Mon Feb 2 21:16:09 EST 2009
Log message for revision 96011:
When a module provides an interface or has an __all__ attribute,
use one of those for the module documentation. Fixes LP #323375.
Also Undid broken link to `savepoint.txt` caused in 3.6.0. The latest
version of the transaction package puts savepoint.txt in the `tests`
subpackage.
Changed:
U zope.app.apidoc/trunk/CHANGES.txt
U zope.app.apidoc/trunk/src/zope/app/apidoc/bookmodule/book.zcml
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/function.py
U zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/module.py
-=-
Modified: zope.app.apidoc/trunk/CHANGES.txt
===================================================================
--- zope.app.apidoc/trunk/CHANGES.txt 2009-02-03 00:30:14 UTC (rev 96010)
+++ zope.app.apidoc/trunk/CHANGES.txt 2009-02-03 02:16:09 UTC (rev 96011)
@@ -5,8 +5,13 @@
3.6.1 (unreleased)
------------------
-- ...
+- When a module provides an interface or has an __all__ attribute,
+ use one of those for the module documentation. Fixes LP #323375.
+- Undid broken link to `savepoint.txt` caused in 3.6.0. The latest
+ version of the transaction package puts savepoint.txt in the `tests`
+ subpackage.
+
3.6.0 (2009-01-31)
------------------
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/bookmodule/book.zcml
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/bookmodule/book.zcml 2009-02-03 00:30:14 UTC (rev 96010)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/bookmodule/book.zcml 2009-02-03 02:16:09 UTC (rev 96011)
@@ -233,7 +233,7 @@
id="savepoints"
title="Savepoints"
parent="transaction"
- doc_path="savepoint.txt"
+ doc_path="tests/savepoint.txt"
/>
<bookchapter
id="doom"
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py 2009-02-03 00:30:14 UTC (rev 96010)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/browser/menu.py 2009-02-03 02:16:09 UTC (rev 96011)
@@ -13,7 +13,7 @@
##############################################################################
"""Code Module Menu
-$Id: browser.py 29143 2005-02-14 22:43:16Z srichter $
+$Id$
"""
__docformat__ = 'restructuredtext'
from zope.component import getUtility
@@ -69,9 +69,7 @@
[{'path': 'zope.app.apidoc.codemodule.browser.Foo',
'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo/'},
{'path': 'zope.app.apidoc.codemodule.browser.Foo2',
- 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo2/'},
- {'path': 'zope.testing.doctest.UnusedFootnoteWarning',
- 'url': 'http://127.0.0.1/zope/testing/doctest/UnusedFootnoteWarning/'}]
+ 'url': 'http://127.0.0.1/zope/app/apidoc/codemodule/browser/Foo2/'}]
>>> menu.request = TestRequest(form={'path': 'o2'})
>>> info = menu.findClasses()
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/function.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/function.py 2009-02-03 00:30:14 UTC (rev 96010)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/function.py 2009-02-03 02:16:09 UTC (rev 96011)
@@ -13,7 +13,7 @@
##############################################################################
"""Function representation for code browser
-$Id: __init__.py 29143 2005-02-14 22:43:16Z srichter $
+$Id$
"""
__docformat__ = 'restructuredtext'
@@ -27,10 +27,14 @@
"""This class represents a function declared in the module."""
implements(ILocation, IFunctionDocumentation)
- def __init__(self, module, name, func):
+ def __init__(self, module, name, func, doc=None):
self.__parent__ = module
self.__name__ = name
self.__func = func
+ if doc is None:
+ self.__doc__ = func.__doc__
+ else:
+ self.__doc__ = doc
def getPath(self):
"""See IFunctionDocumentation."""
@@ -38,7 +42,7 @@
def getDocString(self):
"""See IFunctionDocumentation."""
- return self.__func.__doc__
+ return self.__doc__
def getSignature(self):
"""See IFunctionDocumentation."""
Modified: zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/module.py
===================================================================
--- zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/module.py 2009-02-03 00:30:14 UTC (rev 96010)
+++ zope.app.apidoc/trunk/src/zope/app/apidoc/codemodule/module.py 2009-02-03 02:16:09 UTC (rev 96011)
@@ -21,6 +21,7 @@
import zope
from zope.interface import implements
+from zope.interface import providedBy
from zope.interface.interface import InterfaceClass
from zope.location.interfaces import ILocation
from zope.location import LocationProxy
@@ -74,6 +75,7 @@
if (os.path.isdir(path) and
'__init__.py' in os.listdir(path)):
+ # subpackage
fullname = self._module.__name__ + '.' + file
module = safe_import(fullname)
if module is not None:
@@ -81,6 +83,7 @@
elif os.path.isfile(path) and file.endswith('.py') and \
not file.startswith('__init__'):
+ # module
name = file[:-3]
fullname = self._module.__name__ + '.' + name
module = safe_import(fullname)
@@ -94,26 +97,49 @@
elif os.path.isfile(path) and file.endswith('.txt'):
self._children[file] = TextFile(path, file, self)
- # Setup classes in module, if any are available.
+ # List the classes and functions in module, if any are available.
zope.deprecation.__show__.off()
- for name in self._module.__dict__.keys():
- attr = getattr(self._module, name)
- # We do not want to register duplicates or instances
- if hasattr(attr, '__module__') and \
- attr.__module__ == self._module.__name__:
+ module_decl = providedBy(self._module)
+ ifaces = list(module_decl)
+ if ifaces:
+ # The module has an interface declaration. Yay!
+ names = set()
+ for iface in ifaces:
+ names.update(iface.names())
+ else:
+ names = getattr(self._module, '__all__', None)
+ if names is None:
+ # The module doesn't declare its interface. Boo!
+ # Guess what names to document, avoiding aliases and names
+ # imported from other modules.
+ names = []
+ for name in self._module.__dict__.keys():
+ attr = getattr(self._module, name, None)
+ attr_module = getattr(attr, '__module__', None)
+ if attr_module != self._module.__name__:
+ continue
+ if getattr(attr, '__name__', None) != name:
+ continue
+ names.append(name)
- if not hasattr(attr, '__name__') or \
- attr.__name__ != name:
- continue
+ for name in names:
+ attr = getattr(self._module, name, None)
+ if attr is None:
+ continue
- if isinstance(attr, (types.ClassType, types.TypeType)):
- self._children[name] = Class(self, name, attr)
+ if isinstance(attr, (types.ClassType, types.TypeType)):
+ self._children[name] = Class(self, name, attr)
- if isinstance(attr, InterfaceClass):
- self._children[name] = LocationProxy(attr, self, name)
+ elif isinstance(attr, InterfaceClass):
+ self._children[name] = LocationProxy(attr, self, name)
- elif type(attr) is types.FunctionType:
- self._children[name] = Function(self, name, attr)
+ elif isinstance(attr, types.FunctionType):
+ doc = attr.__doc__
+ if not doc:
+ f = module_decl.get(name)
+ if f is not None:
+ doc = f.__doc__
+ self._children[name] = Function(self, name, attr, doc=doc)
zope.deprecation.__show__.on()
More information about the Checkins
mailing list