From d6b9db9581fd12b15f085e9138e077d31186ee68 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Sun, 14 Oct 2018 20:18:59 -0400 Subject: [PATCH 1/3] tests: Ensure 'member-only' `autodoc_default_options` is respected When specifying the 'member-only' option to `autodoc_default_options`, ensure it is respected. --- tests/test_autodoc.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index f469a6be3..5153ce3e3 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -1569,6 +1569,29 @@ def test_autodoc_default_options_with_values(app): assert ' .. py:attribute:: EnumCls.val3' not in actual assert ' .. py:attribute:: EnumCls.val4' not in actual + # with :member-order: + app.config.autodoc_default_options = { + 'members': None, + 'member-order': 'bysource', + } + actual = do_autodoc(app, 'class', 'target.Class') + assert list(filter(lambda l: '::' in l, actual)) == [ + '.. py:class:: Class(arg)', + ' .. py:attribute:: Class.descr', + ' .. py:method:: Class.meth()', + ' .. py:method:: Class.skipmeth()', + ' .. py:method:: Class.excludemeth()', + ' .. py:attribute:: Class.attr', + ' .. py:attribute:: Class.prop', + ' .. py:attribute:: Class.docattr', + ' .. py:attribute:: Class.udocattr', + ' .. py:attribute:: Class.mdocattr', + ' .. py:classmethod:: Class.moore(a, e, f) -> happiness', + ' .. py:attribute:: Class.inst_attr_inline', + ' .. py:attribute:: Class.inst_attr_comment', + ' .. py:attribute:: Class.inst_attr_string', + ] + # with :special-members: app.config.autodoc_default_options = { 'special-members': '__init__,__iter__', From 9fcef5030accbb4430abe7c8ae4becba089d0f45 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Sun, 14 Oct 2018 20:19:03 -0400 Subject: [PATCH 2/3] autodoc: Respect `member-order` in `autodoc_default_options` as documented In the `autodoc_default_options` documentation, it mentions that `member-order` is respected; however, when setting the key-value pair in `conf.py`, it is not. Thus, add `member-order` as one of the default options respected in `conf.py`. Additionally, update the list of supported options to match the example. --- doc/usage/extensions/autodoc.rst | 7 ++++--- sphinx/ext/autodoc/directive.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/usage/extensions/autodoc.rst b/doc/usage/extensions/autodoc.rst index e604cad28..80783301e 100644 --- a/doc/usage/extensions/autodoc.rst +++ b/doc/usage/extensions/autodoc.rst @@ -383,9 +383,10 @@ There are also new config values that you can set: Setting ``None`` is equivalent to giving the option name in the list format (i.e. it means "yes/true/on"). - The supported options are ``'members'``, ``'undoc-members'``, - ``'private-members'``, ``'special-members'``, ``'inherited-members'``, - ``'show-inheritance'``, ``'ignore-module-all'`` and ``'exclude-members'``. + The supported options are ``'members'``, ``'member-order'``, + ``'undoc-members'``, ``'private-members'``, ``'special-members'``, + ``'inherited-members'``, ``'show-inheritance'``, ``'ignore-module-all'`` and + ``'exclude-members'``. .. versionadded:: 1.8 diff --git a/sphinx/ext/autodoc/directive.py b/sphinx/ext/autodoc/directive.py index e831cab64..cf1f2f47f 100644 --- a/sphinx/ext/autodoc/directive.py +++ b/sphinx/ext/autodoc/directive.py @@ -31,7 +31,7 @@ logger = logging.getLogger(__name__) # common option names for autodoc directives AUTODOC_DEFAULT_OPTIONS = ['members', 'undoc-members', 'inherited-members', 'show-inheritance', 'private-members', 'special-members', - 'ignore-module-all', 'exclude-members'] + 'ignore-module-all', 'exclude-members', 'member-order'] class DummyOptionSpec: From 972a5ef2d831ffe3ac6906f8810e5034ebfb13e3 Mon Sep 17 00:00:00 2001 From: "Eric N. Vander Weele" Date: Sun, 14 Oct 2018 20:19:05 -0400 Subject: [PATCH 3/3] Add Eric N. Vander Weele to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index b7636c4d2..3b1609b85 100644 --- a/AUTHORS +++ b/AUTHORS @@ -68,6 +68,7 @@ Other contributors, listed alphabetically, are: * Antonio Valentino -- qthelp builder, docstring inheritance * Filip Vavera -- napoleon todo directive * Pauli Virtanen -- autodoc improvements, autosummary extension +* Eric N. Vander Weele -- autodoc improvements * Stefan van der Walt -- autosummary extension * Thomas Waldmann -- apidoc module fixes * John Waltman -- Texinfo builder