From f76a25edab7d07dde5673b5c8d6fcdd4ce12e791 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 26 Sep 2024 18:41:17 +0200 Subject: [PATCH] documentation: tighten up writing of trailing newlines. --- documentation/doxygen.py | 16 ++++++++++++---- documentation/python.py | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/documentation/doxygen.py b/documentation/doxygen.py index 3bb13b86..d3ef69eb 100755 --- a/documentation/doxygen.py +++ b/documentation/doxygen.py @@ -4148,7 +4148,9 @@ def run(state: State, *, templates=default_templates, wildcard=default_wildcard, # Add back a trailing newline so we don't need to bother # with patching test files to include a trailing newline to # make Git happy. Can't use keep_trailing_newline because - # that'd add it also for nested templates :( + # that'd add it also for nested templates :( The rendered + # file should never contain a trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') else: parsed = parse_xml(state, file) @@ -4168,7 +4170,9 @@ def run(state: State, *, templates=default_templates, wildcard=default_wildcard, # Add back a trailing newline so we don't need to bother with # patching test files to include a trailing newline to make Git # happy. Can't use keep_trailing_newline because that'd add it - # also for nested templates :( + # also for nested templates :( The rendered file should never + # contain a trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') # Empty index page in case no mainpage documentation was provided so @@ -4195,7 +4199,9 @@ def run(state: State, *, templates=default_templates, wildcard=default_wildcard, # Add back a trailing newline so we don't need to bother with # patching test files to include a trailing newline to make Git # happy. Can't use keep_trailing_newline because that'd add it - # also for nested templates :( + # also for nested templates :( The rendered file should never + # contain a trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') if not state.config['SEARCH_DISABLED']: @@ -4223,7 +4229,9 @@ def run(state: State, *, templates=default_templates, wildcard=default_wildcard, # Add back a trailing newline so we don't need to bother with # patching test files to include a trailing newline to make Git # happy. Can't use keep_trailing_newline because that'd add it - # also for nested templates :( + # also for nested templates :( The rendered file should never + # contain a trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') # Copy all referenced files diff --git a/documentation/python.py b/documentation/python.py index dddc9321..37cb02fc 100755 --- a/documentation/python.py +++ b/documentation/python.py @@ -2060,7 +2060,9 @@ def render(*, config, template: str, url: str, filename: str, env: jinja2.Enviro # Add back a trailing newline so we don't need to bother with # patching test files to include a trailing newline to make Git # happy. Can't use keep_trailing_newline because that'd add it - # also for nested templates :( + # also for nested templates :( The rendered file should never contain a + # trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') def render_module(state: State, path, module, env): @@ -2874,7 +2876,9 @@ def run(basedir, config, *, templates=default_templates, search_add_lookahead_ba # Add back a trailing newline so we don't need to bother with # patching test files to include a trailing newline to make Git # happy. Can't use keep_trailing_newline because that'd add it - # also for nested templates :( + # also for nested templates :( The rendered file should never + # contain a trailing newline on its own. + assert not rendered.endswith('\n') f.write(b'\n') # Copy referenced files -- 2.30.2