Skip to content

Commit

Permalink
Whitespace between releases can be configured in the template. (#553)
Browse files Browse the repository at this point in the history
* Whitespace between releases can be configured in the template.

It used to be baked into the rendering code.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix comment

* Apply suggestions from code review

Co-authored-by: Adi Roiban <[email protected]>

* Don't modify whitespace in draft mode

* Comment that explains the whitespace changes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Adi Roiban <[email protected]>
  • Loading branch information
3 people authored Oct 21, 2023
1 parent 7f37ab5 commit 3f24b6e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,4 @@ def get_indent(text: str) -> str:
else:
done.append(line)

return "\n".join(done).rstrip() + "\n"
return "\n".join(done)
8 changes: 3 additions & 5 deletions src/towncrier/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ def append_to_newsfile(
with news_file.open("w", encoding="utf8", newline="") as f:
if header:
f.write(header)

f.write(content)

if prev_body:
f.write(f"\n\n{prev_body}")
# If there is no previous body that means we're writing a brand new news file.
# We don't want extra whitespace at the end of this new file.
f.write(content + prev_body if prev_body else content.rstrip() + "\n")


def _figure_out_existing_content(
Expand Down
4 changes: 4 additions & 0 deletions src/towncrier/newsfragments/552.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Two newlines are no longer always added between the current release notes and the previous content.
The newlines are now defined only inside the template.

**Important! If you're using a custom template and want to keep the same whitespace between releases, you may have to modify your template.**
6 changes: 5 additions & 1 deletion src/towncrier/templates/default.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ No significant changes.
No significant changes.

{% endif %}
{% endfor %}
{% endfor +%}
{#
This comment adds one more newline at the end of the rendered newsfile content.
In this way the there are 2 newlines between the latest release and the previous release content.
#}
17 changes: 17 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def _test_command(self, command):
- Another orphaned feature
- Orphaned feature
"""
),
)
Expand Down Expand Up @@ -307,6 +309,8 @@ def run_order_scenario(sections, types):
- section-b type-2 (#1)
"""
),
)
Expand Down Expand Up @@ -350,6 +354,8 @@ def run_order_scenario(sections, types):
- section-a type-1 (#1)
"""
),
)
Expand Down Expand Up @@ -576,6 +582,8 @@ def test_projectless_changelog(self):
- Adds levitation (#123)
- Extends levitation (#124)
"""
).lstrip(),
)
Expand Down Expand Up @@ -616,6 +624,8 @@ def test_version_in_config(self):
- Adds levitation (#123)
"""
).lstrip(),
)
Expand Down Expand Up @@ -658,6 +668,8 @@ def test_project_name_in_config(self):
- Adds levitation (#123)
"""
).lstrip(),
)
Expand Down Expand Up @@ -703,6 +715,8 @@ def test_no_package_changelog(self):
- Adds levitation (#123)
"""
).lstrip(),
)
Expand Down Expand Up @@ -1035,6 +1049,8 @@ def test_title_format_custom(self):
- Adds levitation (#123)
- Extends levitation (#124)
"""
)

Expand Down Expand Up @@ -1339,6 +1355,7 @@ def test_with_topline_and_template_and_draft(self):
- Adds levitation
"""
)

Expand Down
14 changes: 14 additions & 0 deletions src/towncrier/test/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def test_basic(self):
~~~~~~~~
- Web fixed. (#3)
"""

template = read_pkg_resource("templates/default.rst")
Expand Down Expand Up @@ -154,6 +156,8 @@ def test_basic(self):
^^^^^^^^
- Web fixed. (#3)
"""

output = render_fragments(
Expand Down Expand Up @@ -229,6 +233,8 @@ def test_markdown(self):
(#2)
- Web fixed. (#3)
"""

template = read_pkg_resource("templates/default.md")
Expand Down Expand Up @@ -291,6 +297,8 @@ def test_markdown(self):
[2]: https://github.com/twisted/towncrier/issues/2
[3]: https://github.com/twisted/towncrier/issues/3
"""

output = render_fragments(
Expand Down Expand Up @@ -332,6 +340,8 @@ def test_issue_format(self):
----
- xxbar, xx1, xx9, xx142
"""

template = read_pkg_resource("templates/default.rst")
Expand Down Expand Up @@ -386,6 +396,8 @@ def test_line_wrapping(self):
- a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a
a a (#3)
"""

template = read_pkg_resource("templates/default.rst")
Expand Down Expand Up @@ -433,6 +445,8 @@ def test_line_wrapping_disabled(self):
- asdf asdf asdf asdf looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong newsfragment. (#1)
- https://google.com/q=?---------------------------------------------------------------------------------------------------- (#2)
- a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a (#3)
""" # NOQA

template = read_pkg_resource("templates/default.rst")
Expand Down

0 comments on commit 3f24b6e

Please sign in to comment.