Autodoc can now exclude single members from documentation

via the ``exclude-members`` option.
This commit is contained in:
Georg Brandl 2009-03-15 23:52:48 +01:00
parent 989f8a593d
commit e517911ac3
4 changed files with 27 additions and 2 deletions

View File

@ -162,6 +162,9 @@ New features added
- Autodoc can document classes as functions now if explicitly
marked with `autofunction`.
- Autodoc can now exclude single members from documentation
via the ``exclude-members`` option.
- Autodoc can now order members either alphabetically (like
previously) or by member type; configurable either with the
config value ``autodoc_member_order`` or a ``member-order``

View File

@ -141,6 +141,12 @@ directive.
.. versionadded:: 0.6
* The directives supporting member documentation also have a
``exclude-members`` option that can be used to exclude single member names
from documentation, if all members are to be documented.
.. versionadded:: 0.6
.. note::
In an :dir:`automodule` directive with the ``members`` option set, only

View File

@ -79,6 +79,12 @@ def members_option(arg):
return ALL
return [x.strip() for x in arg.split(',')]
def members_set_option(arg):
"""Used to convert the :members: option to auto directives."""
if arg is None:
return ALL
return set(x.strip() for x in arg.split(','))
def bool_option(arg):
"""Used to convert flag options to auto directives. (Instead of
directives.flag(), which returns None.)"""
@ -549,6 +555,11 @@ class Documenter(object):
# find out which members are documentable
members_check_module, members = self.get_object_members(want_all)
# remove members given by exclude-members
if self.options.exclude_members:
members = [(membername, member) for (membername, member) in members
if membername not in self.options.exclude_members]
# document non-skipped members
memberdocumenters = []
for (mname, member, isattr) in self.filter_members(members, want_all):
@ -666,7 +677,7 @@ class ModuleDocumenter(Documenter):
'noindex': bool_option, 'inherited-members': bool_option,
'show-inheritance': bool_option, 'synopsis': identity,
'platform': identity, 'deprecated': bool_option,
'member-order': identity,
'member-order': identity, 'exclude-members': members_set_option,
}
@classmethod
@ -818,6 +829,7 @@ class ClassDocumenter(ModuleLevelDocumenter):
'members': members_option, 'undoc-members': bool_option,
'noindex': bool_option, 'inherited-members': bool_option,
'show-inheritance': bool_option, 'member-order': identity,
'exclude-members': members_set_option,
}
@classmethod

View File

@ -37,6 +37,7 @@ def setup_module():
deprecated = False,
members = [],
member_order = 'alphabetic',
exclude_members = set(),
)
directive = Struct(
@ -375,6 +376,7 @@ def test_generate():
assert_processes(should, 'class', 'Class')
should.extend([('method', 'test_autodoc.Class.meth')])
options.members = ['meth']
options.exclude_members = set(['excludemeth'])
assert_processes(should, 'class', 'Class')
should.extend([('attribute', 'test_autodoc.Class.prop'),
('attribute', 'test_autodoc.Class.attr'),
@ -458,7 +460,9 @@ class Class(Base):
def skipmeth(self):
"""Method that should be skipped."""
pass
def excludemeth(self):
"""Method that should be excluded."""
# should not be documented
skipattr = 'foo'