From e517911ac37cf78e0ea02dcd0c8e530d43222289 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 15 Mar 2009 23:52:48 +0100 Subject: [PATCH] Autodoc can now exclude single members from documentation via the ``exclude-members`` option. --- CHANGES | 3 +++ doc/ext/autodoc.rst | 6 ++++++ sphinx/ext/autodoc.py | 14 +++++++++++++- tests/test_autodoc.py | 6 +++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 74838c61b..e15d52809 100644 --- a/CHANGES +++ b/CHANGES @@ -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`` diff --git a/doc/ext/autodoc.rst b/doc/ext/autodoc.rst index 17a2766b2..ff8d189d1 100644 --- a/doc/ext/autodoc.rst +++ b/doc/ext/autodoc.rst @@ -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 diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 43c4b26a9..5c1a06530 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -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 diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index a9e030fef..d7e2f4efc 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -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'