Skip to content

Commit

Permalink
Support runtime concatenation of description strings (#240)
Browse files Browse the repository at this point in the history
This fixes automoduleconfig so this works:

```
DESC = _config(
    "somekey",
    doc=(
        "This is a really long multi-line comment "
        + "that uses runtime string concatenation."
    )
)
```
  • Loading branch information
willkg committed Feb 1, 2024
1 parent 9147e3a commit 1e7ffd2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/everett/sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,10 @@ def extract_value(source: str, val: ast.AST) -> Tuple[str, str]:
return "constant", val.value
if isinstance(val, ast.Name):
return "name", val.id
if isinstance(val, ast.BinOp) and isinstance(val.op, ast.Add):
_, left = extract_value(source, val.left)
_, right = extract_value(source, val.right)
return "binop", left + right
return "unknown", get_value_from_ast_node(source, val)

# Using a dict here avoids the case where configuration options are
Expand Down
10 changes: 10 additions & 0 deletions tests/basic_module_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@ def parse_logging_level(s: str) -> str:
),
}
}

LONG_DESC = _config(
key="long_description",
default="",
doc=(
"This configuration item has a really long description that spans "
+ "several lines so we can test runtime string concatenation.\n\n"
+ "Multiple lines should work, too."
),
)
16 changes: 16 additions & 0 deletions tests/test_sphinxext.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,22 @@ def test_basic(self, tmpdir, capsys):
Woah.
long_description
Parser:
*str*
Default:
""
Required:
No
This configuration item has a really long description that spans
several lines so we can test runtime string concatenation.
Multiple lines should work, too.
cache_location
Parser:
Expand Down

0 comments on commit 1e7ffd2

Please sign in to comment.