Skip to content

Commit 7ef82f5

Browse files
committed
fix: output_file= is now changelog= #77
1 parent b34c39d commit 7ef82f5

File tree

6 files changed

+116
-47
lines changed

6 files changed

+116
-47
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
.. A new scriv changelog fragment.
2+
..
3+
.. Uncomment the section that is right (remove the leading dots).
4+
.. For top level release notes, leave all the headers commented out.
5+
..
6+
.. Removed
7+
.. .......
8+
..
9+
.. - A bullet item for the Removed category.
10+
..
11+
.. Added
12+
.. .....
13+
..
14+
.. - A bullet item for the Added category.
15+
..
16+
Changed
17+
.......
18+
19+
- The ``output_file`` setting is now called ``changelog`` since some uses of
20+
scriv only read the file. An ``output_file`` entry in the config file will
21+
still work to set the name. Closes `issue 77`_.
22+
23+
.. _issue 77: https://github.com/nedbat/scriv/issues/77
24+
25+
..
26+
.. Deprecated
27+
.. ..........
28+
..
29+
.. - A bullet item for the Deprecated category.
30+
..
31+
.. Fixed
32+
.. .....
33+
..
34+
.. - A bullet item for the Fixed category.
35+
..
36+
.. Security
37+
.. ........
38+
..
39+
.. - A bullet item for the Security category.
40+
..

docs/commands.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ date.
136136
Instead of using the title template, you can provide an exact title to use for
137137
the new entry with the ``--title`` option.
138138

139-
The output file is specified by the :ref:`config_output_file` setting. Scriv
139+
The output file is specified by the :ref:`config_changelog` setting. Scriv
140140
looks in the file for a special marker (usually in a comment) to determine
141141
where to insert the new entry. The marker is "scriv-insert-here", but can be
142142
changed with the :ref:`config_insert_marker` setting. Using a marker like

docs/configuration.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ See :ref:`categories`.
228228
Default: ``Removed, Added, Changed, Deprecated, Fixed, Security``
229229

230230

231+
.. _config_changelog:
232+
233+
changelog
234+
---------
235+
236+
The changelog file managed and read by scriv. The old name
237+
for this setting is :ref:`output_file <deprecated_config>`.
238+
239+
Default: ``CHANGELOG.${config:format}``
240+
241+
231242
.. _config_end_marker:
232243

233244
end_marker
@@ -338,16 +349,6 @@ The `Jinja`_ template to use for new fragments.
338349
Default: ``file: new_fragment.${config:format}.j2``
339350

340351

341-
.. _config_output_file:
342-
343-
output_file
344-
-----------
345-
346-
The changelog file updated by ":ref:`cmd_collect`".
347-
348-
Default: ``CHANGELOG.${config:format}``
349-
350-
351352
.. _config_rst_header_chars:
352353

353354
rst_header_chars
@@ -384,7 +385,18 @@ source file.
384385

385386
Default: (empty)
386387

387-
.. [[[end]]] (checksum: ac66a08483626b8550ebec22bbc3af04)
388+
.. [[[end]]] (checksum: acce6a163b5e8567a695069a8b5146e3)
389+
390+
391+
.. _deprecated_config:
392+
393+
Deprecated Settings
394+
===================
395+
396+
Some names in the config file have been updated. The old names will continue to
397+
work, but the new names are preferred:
398+
399+
- ``output_file`` is now ``changelog``.
388400

389401

390402
.. _git_settings:

src/scriv/config.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ class _Options:
7272
},
7373
)
7474

75-
output_file = attr.ib(
75+
changelog = attr.ib(
7676
type=str,
7777
default="CHANGELOG.${config:format}",
7878
metadata={
7979
"doc": """\
80-
The changelog file updated by ":ref:`cmd_collect`".
80+
The changelog file managed and read by scriv. The old name
81+
for this setting is :ref:`output_file <deprecated_config>`.
8182
""",
8283
},
8384
)
@@ -294,6 +295,20 @@ def read(cls) -> Config:
294295
attr.validate(config._options)
295296
return config
296297

298+
def get_set_option(self, scriv_data, config_name, opt_name):
299+
"""
300+
Set one option from a config file setting.
301+
"""
302+
try:
303+
val: Any = scriv_data[config_name]
304+
except KeyError:
305+
pass
306+
else:
307+
attrdef = attr.fields_dict(_Options)[opt_name]
308+
if callable(attrdef.converter):
309+
val = attrdef.converter(val)
310+
setattr(self._options, opt_name, val)
311+
297312
def read_one_config(self, configfile: str) -> None:
298313
"""
299314
Read one configuration file, adding values to `self`.
@@ -306,18 +321,19 @@ def read_one_config(self, configfile: str) -> None:
306321
return
307322
logger.debug(f"{configfile} was read")
308323

309-
section_names = ["scriv", "tool.scriv"]
310324
section_name = next(
311-
(name for name in section_names if parser.has_section(name)), None
325+
(
326+
name
327+
for name in ["scriv", "tool.scriv"]
328+
if parser.has_section(name)
329+
),
330+
None,
312331
)
313332
if section_name:
333+
scriv_data = parser[section_name]
314334
for attrdef in attr.fields(_Options):
315-
try:
316-
val: Any = parser[section_name][attrdef.name]
317-
except KeyError:
318-
pass
319-
else:
320-
setattr(self._options, attrdef.name, val)
335+
self.get_set_option(scriv_data, attrdef.name, attrdef.name)
336+
self.get_set_option(scriv_data, "output_file", "changelog")
321337

322338
def read_one_toml(self, tomlfile: str) -> None:
323339
"""
@@ -351,14 +367,8 @@ def read_one_toml(self, tomlfile: str) -> None:
351367
# No settings for us
352368
return
353369
for attrdef in attr.fields(_Options):
354-
try:
355-
val = scriv_data[attrdef.name]
356-
except KeyError:
357-
pass
358-
else:
359-
if callable(attrdef.converter):
360-
val = attrdef.converter(val)
361-
setattr(self._options, attrdef.name, val)
370+
self.get_set_option(scriv_data, attrdef.name, attrdef.name)
371+
self.get_set_option(scriv_data, "output_file", "changelog")
362372

363373
def resolve_value(self, value: str) -> str:
364374
"""

src/scriv/scriv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def combine_fragments(self, fragments: Iterable[Fragment]) -> SectionDict:
6767
def changelog(self) -> Changelog:
6868
"""Get the Changelog object."""
6969
return Changelog(
70-
path=Path(self.config.output_file),
70+
path=Path(self.config.changelog),
7171
config=self.config,
7272
)
7373

tests/test_config.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@
1313

1414
CONFIG1 = """\
1515
[scriv]
16-
output_file = README.md
16+
changelog = README.md
1717
categories = New, Different, Gone, Bad
1818
"""
1919

20+
OLD_CONFIG1 = CONFIG1.replace("changelog = ", "output_file = ")
21+
2022
CONFIG2 = """\
2123
[someotherthing]
2224
no_idea = what this is
2325
2426
[tool.scriv]
25-
output_file = README.md
27+
changelog = README.md
2628
categories =
2729
New
2830
Different
@@ -59,7 +61,7 @@
5961
GENERIC_TOML_CONFIG
6062
+ """
6163
[tool.scriv]
62-
output_file = "README.md"
64+
changelog = "README.md"
6365
categories = [
6466
"New",
6567
"Different",
@@ -73,6 +75,8 @@
7375
"""
7476
)
7577

78+
OLD_TOML_CONFIG = TOML_CONFIG.replace("changelog = ", "output_file = ")
79+
7680

7781
def test_defaults(temp_dir):
7882
# No configuration files anywhere, just get all the defaults.
@@ -90,7 +94,7 @@ def test_defaults(temp_dir):
9094
"Fixed",
9195
"Security",
9296
]
93-
assert config.output_file == "CHANGELOG.rst"
97+
assert config.changelog == "CHANGELOG.rst"
9498
assert config.insert_marker == "scriv-insert-here"
9599
assert config.rst_header_chars == "=-"
96100
assert config.md_header_level == "1"
@@ -100,11 +104,12 @@ def test_defaults(temp_dir):
100104
assert config.version == ""
101105

102106

103-
def test_reading_config(temp_dir):
104-
(temp_dir / "setup.cfg").write_text(CONFIG1)
107+
@pytest.mark.parametrize("config_text", [CONFIG1, OLD_CONFIG1])
108+
def test_reading_config(config_text, temp_dir):
109+
(temp_dir / "setup.cfg").write_text(config_text)
105110
config = Config.read()
106111
assert config.fragment_directory == "changelog.d"
107-
assert config.output_file == "README.md"
112+
assert config.changelog == "README.md"
108113
assert config.categories == ["New", "Different", "Gone", "Bad"]
109114

110115

@@ -227,7 +232,7 @@ def test_override_default_name(changelog_d):
227232
def test_file_reading(changelog_d):
228233
# Any setting can be read from a file, even where it doesn't make sense.
229234
(changelog_d / "hello.txt").write_text("Xyzzy")
230-
text = Config(output_file="file:hello.txt").output_file
235+
text = Config(changelog="file:hello.txt").changelog
231236
assert text == "Xyzzy"
232237

233238

@@ -301,7 +306,7 @@ def test_rst_chars_is_two_chars(chars):
301306
def test_md_format(changelog_d):
302307
(changelog_d / "scriv.ini").write_text("[scriv]\nformat = md\n")
303308
config = Config.read()
304-
assert config.output_file == "CHANGELOG.md"
309+
assert config.changelog == "CHANGELOG.md"
305310
template = re.sub(r"\s+", " ", config.new_fragment_template)
306311
assert template.startswith("<!-- A new scriv changelog fragment.")
307312

@@ -312,9 +317,11 @@ class TestTomlConfig:
312317
"""
313318

314319
@pytest.mark.skipif(tomllib is None, reason="No TOML support installed")
315-
def test_reading_toml_file(self, temp_dir):
316-
(temp_dir / "pyproject.toml").write_text(TOML_CONFIG)
320+
@pytest.mark.parametrize("config_text", [TOML_CONFIG, OLD_TOML_CONFIG])
321+
def test_reading_toml_file(self, config_text, temp_dir):
322+
(temp_dir / "pyproject.toml").write_text(config_text)
317323
config = Config.read()
324+
assert config.changelog == "README.md"
318325
assert config.categories == ["New", "Different", "Gone", "Bad"]
319326

320327
def test_toml_without_us(self, temp_dir):
@@ -371,12 +378,12 @@ def test_command_running(mocker, cmd_output, result):
371378
mocker.patch(
372379
"scriv.config.run_shell_command", lambda cmd: (True, cmd_output)
373380
)
374-
text = Config(output_file="command: doesnt-matter").output_file
381+
text = Config(changelog="command: doesnt-matter").changelog
375382
assert text == result
376383

377384

378385
def test_real_command_running():
379-
text = Config(output_file="command: echo Xyzzy 2 3").output_file
386+
text = Config(changelog="command: echo Xyzzy 2 3").changelog
380387
assert text == "Xyzzy 2 3"
381388

382389

@@ -385,15 +392,15 @@ def test_real_command_running():
385392
[
386393
(
387394
"xyzzyplugh",
388-
"Couldn't read 'output_file' setting: Command 'xyzzyplugh' failed:",
395+
"Couldn't read 'changelog' setting: Command 'xyzzyplugh' failed:",
389396
),
390397
(
391398
"'hi!2><",
392-
"Couldn't read 'output_file' setting: Command \"'hi!2><\" failed:",
399+
"Couldn't read 'changelog' setting: Command \"'hi!2><\" failed:",
393400
),
394401
],
395402
)
396403
def test_bad_command(fake_run_command, bad_cmd, msg_rx):
397404
# Any setting can be the output of a command.
398405
with pytest.raises(ScrivException, match=msg_rx):
399-
_ = Config(output_file=f"command: {bad_cmd}").output_file
406+
_ = Config(changelog=f"command: {bad_cmd}").changelog

0 commit comments

Comments
 (0)