Skip to content

Commit

Permalink
Support autocomponentconfig for components with no options (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg committed Oct 30, 2024
1 parent a0abf58 commit b4622cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------------
Expand Down
13 changes: 8 additions & 5 deletions src/everett/sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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)


Expand Down
7 changes: 7 additions & 0 deletions tests/basic_component_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Config:
user = Option()


class ComponentNoOptions:
"""Basic component with no options."""

class Config:
pass


class ComponentSubclass(ComponentBasic):
"""A different docstring."""

Expand Down
18 changes: 18 additions & 0 deletions tests/test_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit b4622cd

Please sign in to comment.