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

fix: don't strip trailing newlines when rendering fragment templates #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions changelog.d/20231210_233839_dpb_keep_trailing_newline.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixed
.....

- A final newline is no longer stripped when rendering the new fragment
template, fixing `issue 108`_.

.. _issue 108: https://github.com/nedbat/scriv/issues/108
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ install_requires =
attrs
click
click-log
jinja2
jinja2>=2.7
markdown-it-py
requests
# end_install_requires
Expand Down
3 changes: 2 additions & 1 deletion src/scriv/scriv.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def _new_fragment_path(config: Config) -> Path:
def _new_fragment_content(config: Config) -> str:
"""Produce the initial content of a scriv fragment."""
return jinja2.Template(
textwrap.dedent(config.new_fragment_template)
textwrap.dedent(config.new_fragment_template),
keep_trailing_newline=True,
).render(config=config)


Expand Down
8 changes: 8 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ def test_new_fragment_contents_md(self):
assert "### Added\n" in content
assert all(cat in content for cat in scriv.config.categories)

def test_final_newline_in_template_preserved(self, changelog_d):
(changelog_d / "new_fragment.j2").write_text("Custom template.\n")
scriv = Scriv(
config=Config(new_fragment_template="file: new_fragment.j2")
)
content = scriv.new_fragment().content
assert content == "Custom template.\n"


class TestCreate:
"""
Expand Down