Normalize rendered template output for pre-commit#548
Merged
Conversation
Bakery's Jinja-rendered files (Containerfiles, goss.yaml, scripts, and bakery.yaml itself) could ship with trailing whitespace or a missing trailing newline, failing the trailing-whitespace and end-of-file-fixer pre-commit hooks in consuming repos. Release PRs in images-connect (#77, #87) failed CI for exactly this reason. Add normalize_rendered_output() that strips trailing spaces and tabs from each line and ensures a single trailing newline, matching the output of those two pre-commit hooks. Apply it at every site that writes a rendered template: - ImageVersion.render_files (Containerfile and other templates) - ImageMatrix.render_files (Containerfile and other templates) - BakeryConfig.new (initial bakery.yaml) - BakeryConfig.write (updates to bakery.yaml, replacing the inline re.sub strip added in 48dea80) - BakeryConfigDocument when scaffolding a new Containerfile template Also drop the dead render_kwargs["trim_blocks"] = True branch from ImageVersion and ImageMatrix. trim_blocks is a Jinja2 Environment option, not a Template.render() argument, so passing it through .render() was a silent no-op that just added it to the template context. Removing it doesn't change rendered output because it never took effect; the new normalize step covers the same intent more robustly.
ianpittwood
approved these changes
May 27, 2026
Contributor
ianpittwood
left a comment
There was a problem hiding this comment.
LGTM, thanks for fixing this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bakery's Jinja-rendered files (Containerfiles, goss.yaml, scripts, and bakery.yaml itself) could ship with trailing whitespace or a missing trailing newline, failing
trailing-whitespaceandend-of-file-fixerpre-commit hooks in consuming repos. Two release PRs failed CI for exactly this reason:The root cause was two compounding bugs in the renderer. First,
ImageVersion.render_filesandImageMatrix.render_filestried to enabletrim_blocksfor Containerfile templates by passing it totpl.render(trim_blocks=True)— buttrim_blocksis a Jinja2Environmentoption, not aTemplate.render()argument, so it was a silent no-op that just landed in the template context. Second, no rendered-template write path normalized whitespace exceptBakeryConfig.write(), which had a one-offre.subadded after the first failure. Everything else (Containerfiles viaversion.py/matrix.py, goss.yaml, scripts, scaffoldedbakery.yaml) wrote raw Jinja output, so{% for %} ... {% endfor %}blocks left lines containing only their leading indent — exactly what PR #87 caught inconnect/2026.04/test/goss.yaml.normalize_rendered_output()inposit_bakery/config/templating/render.pystrips trailing spaces and tabs from each line and ensures a single trailing newline, matching what the two pre-commit hooks produce. It's now applied at every rendered-file write site, andBakeryConfig.write()'s inlinere.subis replaced by it for consistency. The deadrender_kwargs["trim_blocks"] = Truebranch is removed since it never took effect; the new normalize step covers the same intent more robustly.Verified by re-rendering all images in
images-connect,images-package-manager, andimages-workbenchagainst the patched bakery — full pre-commit suite passes on all three.