diff --git a/HISTORY.rst b/HISTORY.rst index 9c70ee6..592a2a4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -18,6 +18,8 @@ Fixes and features: * Add ``ChoiceOf`` parser for enforcing configuration values belong in specified value domain. (#253) +* Fix ``autocomponentconfig`` to support components with no options. (#244) + 3.3.0 (November 6th, 2023) -------------------------- diff --git a/src/everett/sphinxext.py b/src/everett/sphinxext.py index 21ce65b..3fe07f7 100644 --- a/src/everett/sphinxext.py +++ b/src/everett/sphinxext.py @@ -383,11 +383,11 @@ def generate_docs( self.add_line(indent + line, src[0], src[1]) self.add_line("", "") - if "show-table" in self.options: + if "show-table" in self.options and option_data: self.add_line(indent + "Configuration summary:", sourcename) self.add_line("", sourcename) - # First build a table of metric items + # Build a table of metric items table: list[list[str]] = [] table.append(["Setting", "Parser", "Required?"]) for option_item in option_data: @@ -408,10 +408,9 @@ def generate_docs( self.add_line(indent + "Configuration options:", sourcename) self.add_line("", sourcename) + sourcename = "class definition" if option_data: - # Now list the options - sourcename = "class definition" - + # List the options and details for option_item in option_data: key = option_item["key"] self.add_line(f"{indent}.. everett:option:: {key}", sourcename) @@ -432,6 +431,10 @@ def generate_docs( self.add_line(f"{indent} {doc_line}", sourcename) self.add_line("", sourcename) + else: + # There are no options + self.add_line(f"{indent}No configuration options.", sourcename) + self.add_line("", sourcename) diff --git a/tests/basic_component_config.py b/tests/basic_component_config.py index 4fb43ea..90b98c0 100644 --- a/tests/basic_component_config.py +++ b/tests/basic_component_config.py @@ -16,6 +16,13 @@ class Config: user = Option() +class ComponentNoOptions: + """Basic component with no options.""" + + class Config: + pass + + class ComponentSubclass(ComponentBasic): """A different docstring.""" diff --git a/tests/test_sphinxext.py b/tests/test_sphinxext.py index 9432a4c..8849133 100644 --- a/tests/test_sphinxext.py +++ b/tests/test_sphinxext.py @@ -115,6 +115,24 @@ def test_basic(self, tmpdir, capsys): assert "WARNING" not in captured.out assert "WARNING" not in captured.err + def test_no_option_data(self, tmpdir, capsys): + rst = dedent( + """\ + .. autocomponentconfig:: basic_component_config.ComponentNoOptions + """ + ) + + assert run_sphinx(tmpdir, rst) == dedent( + """\ + component basic_component_config.ComponentNoOptions + + No configuration options. + """ + ) + captured = capsys.readouterr() + assert "WARNING" not in captured.out + assert "WARNING" not in captured.err + def test_hide_name(self, tmpdir, capsys): # Test hide-name rst = dedent(