Skip to content

Commit

Permalink
Fix newlines and add explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
hynek committed Sep 3, 2022
1 parent e13c567 commit 710407e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/towncrier/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ def append_to_newsfile(
if top_line and top_line in prev_body:
raise ValueError("It seems you've already produced newsfiles for this version?")

with open(news_file, "w", encoding="utf8") as f:
# Leave newlines alone. This probably leads to inconsistent newlines,
# because we've loaded existing content with universal newlines, but that's
# the original behavior.
with open(news_file, "w", encoding="utf8", newline="") as f:
if header:
f.write(header)

Expand All @@ -55,6 +58,8 @@ def _figure_out_existing_content(news_file, start_string, single_file):
# Non-existent files have no existing content.
return "", ""

# If we didn't use universal newlines here, we wouldn't find *start_string*
# which usually contains a `\n`.
with open(news_file, encoding="utf8") as f:
content = f.read()

Expand Down

0 comments on commit 710407e

Please sign in to comment.