Repository: twisted/towncrier
Pull request #553 (2023-10-19 22:14:50)

Whitespace between releases can be configured in the template.
It used to be baked into the rendering code.

# Description
<!-- add a short summary if necessary; mention issue numbers -->

Implementation of #552 

# Checklist
<!-- add a "X" inside the brackets to confirm -->
* [x] Make sure changes are covered by existing or new tests.
* [x] For at least one Python version, make sure local test run is green.
* [x] Create a file in `src/towncrier/newsfragments/`. Describe your
  change and include important information. Your change will be included in the public release notes.
* [ ] Make sure all GitHub Actions checks are green (they are automatically checking all of the above).
* [ ] Ensure `docs/tutorial.rst` is still up-to-date.
* [ ] If you add new **CLI arguments** (or change the meaning of existing ones), make sure `docs/cli.rst` reflects those changes.
* [ ] If you add new **configuration options** (or change the meaning of existing ones), make sure `docs/configuration.rst` reflects those changes.


iliakur: @adiroiban this is ready for review, thanks!
adiroiban: Thanks for the extra comment. Looks good. I will merge.

Patch:
diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py
index d1b14db..6f8f166 100644
--- a/src/towncrier/_builder.py
+++ b/src/towncrier/_builder.py
@@ -335,4 +335,4 @@ def render_fragments(
         else:
             done.append(line)
 
-    return "\n".join(done).rstrip() + "\n"
+    return "\n".join(done)
diff --git a/src/towncrier/_writer.py b/src/towncrier/_writer.py
index 9211911..4145e3d 100644
--- a/src/towncrier/_writer.py
+++ b/src/towncrier/_writer.py
@@ -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(
diff --git a/src/towncrier/newsfragments/552.feature b/src/towncrier/newsfragments/552.feature
new file mode 100644
index 0000000..56b9f4a
--- /dev/null
+++ b/src/towncrier/newsfragments/552.feature
@@ -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.**
diff --git a/src/towncrier/templates/default.md b/src/towncrier/templates/default.md
index 45f7a39..9afb5c4 100644
--- a/src/towncrier/templates/default.md
+++ b/src/towncrier/templates/default.md
@@ -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.
+#}


Test patch:
diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py
index d456126..aa483ba 100644
--- a/src/towncrier/test/test_build.py
+++ b/src/towncrier/test/test_build.py
@@ -76,6 +76,8 @@ class TestCli(TestCase):
                 - Another orphaned feature
                 - Orphaned feature
 
+
+
                 """
             ),
         )
@@ -307,6 +309,8 @@ class TestCli(TestCase):
 
                   - section-b type-2 (#1)
 
+
+
             """
             ),
         )
@@ -350,6 +354,8 @@ class TestCli(TestCase):
 
                   - section-a type-1 (#1)
 
+
+
             """
             ),
         )
@@ -576,6 +582,8 @@ class TestCli(TestCase):
             - Adds levitation (#123)
             - Extends levitation (#124)
 
+
+
             """
             ).lstrip(),
         )
@@ -616,6 +624,8 @@ class TestCli(TestCase):
 
             - Adds levitation (#123)
 
+
+
             """
             ).lstrip(),
         )
@@ -658,6 +668,8 @@ class TestCli(TestCase):
 
             - Adds levitation (#123)
 
+
+
             """
             ).lstrip(),
         )
@@ -703,6 +715,8 @@ class TestCli(TestCase):
 
             - Adds levitation (#123)
 
+
+
             """
             ).lstrip(),
         )
@@ -1035,6 +1049,8 @@ Deprecations and Removals
             - Adds levitation (#123)
             - Extends levitation (#124)
 
+
+
         """
         )
 
@@ -1339,6 +1355,7 @@ Deprecations and Removals
 
             - Adds levitation
 
+
         """
         )
 
diff --git a/src/towncrier/test/test_format.py b/src/towncrier/test/test_format.py
index 61e6d88..a1efefb 100644
--- a/src/towncrier/test/test_format.py
+++ b/src/towncrier/test/test_format.py
@@ -107,6 +107,8 @@ Bugfixes
 ~~~~~~~~
 
 - Web fixed. (#3)
+
+
 """
 
         template = read_pkg_resource("templates/default.rst")
@@ -154,6 +156,8 @@ Bugfixes
 ^^^^^^^^
 
 - Web fixed. (#3)
+
+
 """
 
         output = render_fragments(
@@ -229,6 +233,8 @@ No significant changes.
 
   (#2)
 - Web fixed. (#3)
+
+
 """
 
         template = read_pkg_resource("templates/default.md")
@@ -291,6 +297,8 @@ No significant changes.
 
 [2]: https://github.com/twisted/towncrier/issues/2
 [3]: https://github.com/twisted/towncrier/issues/3
+
+
 """
 
         output = render_fragments(
@@ -332,6 +340,8 @@ Misc
 ----
 
 - xxbar, xx1, xx9, xx142
+
+
 """
 
         template = read_pkg_resource("templates/default.rst")
@@ -386,6 +396,8 @@ Features
 - 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")
@@ -433,6 +445,8 @@ Features
 - 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")