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

Final newline stripped from fragment template #108

Open
SpecLad opened this issue Oct 4, 2023 · 1 comment · May be fixed by #119
Open

Final newline stripped from fragment template #108

SpecLad opened this issue Oct 4, 2023 · 1 comment · May be fixed by #119

Comments

@SpecLad
Copy link

SpecLad commented Oct 4, 2023

When a custom new fragment template is used, scriv strips the final newline from it when it creates the fragment. For example, create the following scriv.ini:

[tool.scriv]
new_fragment_template = file: fragment.j2

Then create fragment.j2 as follows:

$ echo foobar > changelog.d/fragment.j2
00000000: 666f 6f62 6172 0a                        foobar. <-- note that the file ends with a newline

Now create a fragment and examine it:

$ scriv create
Creating changelog.d/20231004_201751_roman.rst
$ xxd changelog.d/20231004_201751_roman.rst
00000000: 666f 6f62 6172                           foobar <-- newline is gone!

This is mildly annoying, as I'd like all my text files to end with a newline.

@kurtmckee
Copy link
Contributor

The following is not a solution, but a general tip to enforce styles and preferences on projects.

To enforce this across all files -- regardless of what tool or generates the file -- you can use the "end-of-file-fixer" pre-commit hook to ensure that all text files end with a newline, a la:

repos:
  - repo: "https://github.com/pre-commit/pre-commit-hooks"
    rev: "v4.5.0"
    hooks:
      - id: "end-of-file-fixer"

That fixer will enforce that all files end with a newline before they can be committed to the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants