diff --git a/CHANGES b/CHANGES index 9af83621279..a5725b0d518 100644 --- a/CHANGES +++ b/CHANGES @@ -16,7 +16,7 @@ Features added * #9815: html theme: Wrap sidebar components in div to allow customizing their layout via CSS * #9831: Autosummary now documents only the members specified in a module's - ``__all__`` attribute if :confval:`autosummary_ignore___all__` is set to + ``__all__`` attribute if :confval:`autosummary_ignore_module_all` is set to ``False``. The default behaviour is unchanged. Autogen also now supports this behavior with the ``--respect-module-all`` switch. diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index b8691b3dae3..298c9013802 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -826,6 +826,6 @@ def setup(app: Sphinx) -> Dict[str, Any]: app.add_config_value('autosummary_mock_imports', lambda config: config.autodoc_mock_imports, 'env') app.add_config_value('autosummary_imported_members', [], False, [bool]) - app.add_config_value('autosummary_ignore___all__', True, 'env', bool) + app.add_config_value('autosummary_ignore_module_all', True, 'env', bool) return {'version': sphinx.__display_version__, 'parallel_read_safe': True} diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py index 05363f3c71b..dd712d80281 100644 --- a/sphinx/ext/autosummary/generate.py +++ b/sphinx/ext/autosummary/generate.py @@ -68,7 +68,7 @@ def __init__(self, translator: NullTranslations) -> None: self.config.add('autosummary_context', {}, True, None) self.config.add('autosummary_filename_map', {}, True, None) - self.config.add('autosummary_ignore___all__', True, 'env', bool) + self.config.add('autosummary_ignore_module_all', True, 'env', bool) self.config.init_values() def emit_firstresult(self, *args: Any) -> None: @@ -219,7 +219,7 @@ def scan(self, imported_members: bool) -> List[str]: elif imported is False: # list not-imported members members.append(name) - elif '__all__' in dir(self.object) and not self.app.config.autosummary_ignore___all__: + elif '__all__' in dir(self.object) and not self.app.config.autosummary_ignore_module_all: # list members that have __all__ set members.append(name) @@ -228,9 +228,9 @@ def scan(self, imported_members: bool) -> List[str]: def members_of(conf: Config, obj: Any) -> Sequence[str]: """Get the members of ``obj``, possibly ignoring the ``__all__`` module attribute - Follows the ``conf.autosummary_ignore___all__`` setting.""" + Follows the ``conf.autosummary_ignore_module_all`` setting.""" - if conf.autosummary_ignore___all__: + if conf.autosummary_ignore_module_all: return dir(obj) else: return getall(obj) or dir(obj) @@ -645,8 +645,8 @@ def get_parser() -> argparse.ArgumentParser: dest='imported_members', default=False, help=__('document imported members (default: ' '%(default)s)')) - parser.add_argument('-a', '--respect-module-all', action='store_false', - dest='ignore___all__', default=True, + parser.add_argument('-a', '--respect-module-all', action='store_true', + dest='respect_module_all', default=False, help=__('document exactly the members in module __all__ attribute. ' '(default: %(default)s)')) @@ -665,7 +665,7 @@ def main(argv: List[str] = sys.argv[1:]) -> None: if args.templates: app.config.templates_path.append(path.abspath(args.templates)) - app.config.autosummary_ignore___all__ = args.ignore___all__ + app.config.autosummary_ignore_module_all = not args.respect_module_all generate_autosummary_docs(args.source_file, args.output_dir, '.' + args.suffix, diff --git a/tests/test_ext_autosummary.py b/tests/test_ext_autosummary.py index dd9b8c51930..0c35b9e3eea 100644 --- a/tests/test_ext_autosummary.py +++ b/tests/test_ext_autosummary.py @@ -238,7 +238,7 @@ def test_autosummary_generate_content_for_module(app): def test_autosummary_generate_content_for_module___all__(app): import autosummary_dummy_module template = Mock() - app.config.autosummary_ignore___all__ = False + app.config.autosummary_ignore_module_all = False generate_autosummary_content('autosummary_dummy_module', autosummary_dummy_module, None, template, None, False, app, False, {})