Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow integer md_header_level #137

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Added
.....

- Configuration setting ``md_header_level`` is allowed to be an integer in
TOML files, closing `issue 90`_.

.. _issue 90: https://github.com/nedbat/scriv/issues/90
3 changes: 3 additions & 0 deletions src/scriv/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ class _Options:
type=str,
default="1",
validator=attr.validators.matches_re(r"[123456]"),
converter=attr.converters.optional(str),
metadata={
"doc": """\
A number: for Markdown changelog files, this is the heading
Expand Down Expand Up @@ -352,6 +353,8 @@ def read_one_toml(self, tomlfile: str) -> None:
except KeyError:
pass
else:
if callable(attrdef.converter):
val = attrdef.converter(val)
setattr(self._options, attrdef.name, val)

def resolve_value(self, value: str) -> str:
Expand Down
13 changes: 13 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"Gone",
"Bad",
]
# other scriv options

["more stuff"]
value = 17
Expand Down Expand Up @@ -345,6 +346,18 @@ def test_no_toml_installed_no_settings(self, temp_dir):
config = Config.read()
assert config.categories[0] == "Removed"

@pytest.mark.skipif(tomllib is None, reason="No TOML support installed")
def test_nonstring_options(self, temp_dir):
# Some config options are allowed to be e.g. TOML integers; for these,
# both string and non-string values are valid.
marker = "# other scriv options"
for value in ('"6"', "6"):
custom = f"{marker}\nmd_header_level = {value}"
CUSTOM_TOML = TOML_CONFIG.replace(marker, custom)
(temp_dir / "pyproject.toml").write_text(CUSTOM_TOML)
config = Config.read()
assert config.md_header_level == "6"


@pytest.mark.parametrize(
"cmd_output, result",
Expand Down