mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Added `autodoc_default_flags
` config value, which can be used
to select default flags for all autodoc directives.
This commit is contained in:
parent
750c3622fd
commit
fab92b215a
3
CHANGES
3
CHANGES
@ -8,6 +8,9 @@ Release 1.0 (in development)
|
||||
|
||||
* Added single-file HTML builder.
|
||||
|
||||
* Added ``autodoc_default_flags`` config value, which can be used
|
||||
to select default flags for all autodoc directives.
|
||||
|
||||
* Added ``tab-width`` option to ``literalinclude`` directive.
|
||||
|
||||
* The ``html_sidebars`` config value can now contain patterns as
|
||||
|
@ -228,6 +228,24 @@ There are also new config values that you can set:
|
||||
|
||||
.. versionadded:: 0.6
|
||||
|
||||
.. confval:: autodoc_default_flags
|
||||
|
||||
This value is a list of autodoc directive flags that should be automatically
|
||||
applied to all autodoc directives. The supported flags are ``'members'``,
|
||||
``'undoc-members'``, ``'inherited-members'`` and ``'show-inheritance'``.
|
||||
|
||||
If you set one of these flags in this config value, you can use a negated
|
||||
form, :samp:`'no-{flag}'`, in an autodoc directive, to disable it once.
|
||||
For example, if ``autodoc_default_flags`` is set to ``['members',
|
||||
'undoc-members']``, and you write a directive like this::
|
||||
|
||||
.. automodule:: foo
|
||||
:no-undoc-members:
|
||||
|
||||
the directive will be interpreted as if only ``:members:`` was given.
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
|
||||
Docstring preprocessing
|
||||
-----------------------
|
||||
|
@ -1098,6 +1098,10 @@ class AutoDirective(Directive):
|
||||
# a registry of type -> getattr function
|
||||
_special_attrgetters = {}
|
||||
|
||||
# flags that can be given in autodoc_default_flags
|
||||
_default_flags = set(['members', 'undoc-members', 'inherited-members',
|
||||
'show-inheritance'])
|
||||
|
||||
# standard docutils directive settings
|
||||
has_content = True
|
||||
required_arguments = 1
|
||||
@ -1120,6 +1124,14 @@ class AutoDirective(Directive):
|
||||
# find out what documenter to call
|
||||
objtype = self.name[4:]
|
||||
doc_class = self._registry[objtype]
|
||||
# add default flags
|
||||
for flag in self._default_flags:
|
||||
if flag not in doc_class.option_spec:
|
||||
continue
|
||||
negated = self.options.pop('no-' + flag, 'not given') is None
|
||||
if flag in self.env.config.autodoc_default_flags and \
|
||||
not negated:
|
||||
self.options[flag] = None
|
||||
# process the options with the selected documenter's option_spec
|
||||
self.genopt = Options(assemble_option_dict(
|
||||
self.options.items(), doc_class.option_spec))
|
||||
@ -1177,6 +1189,7 @@ def setup(app):
|
||||
|
||||
app.add_config_value('autoclass_content', 'class', True)
|
||||
app.add_config_value('autodoc_member_order', 'alphabetic', True)
|
||||
app.add_config_value('autodoc_default_flags', [], True)
|
||||
app.add_event('autodoc-process-docstring')
|
||||
app.add_event('autodoc-process-signature')
|
||||
app.add_event('autodoc-skip-member')
|
||||
|
Loading…
Reference in New Issue
Block a user