From 00e961f52d1af1d5bcbbf35774ee7702f53c2d65 Mon Sep 17 00:00:00 2001 From: ccp_zeulix Date: Tue, 4 Jun 2024 14:54:04 +0000 Subject: [PATCH] Version 0.8.0 - Line ending change ## Changed - `FileRenderer` (and thus `DirectoryRenderer`) now use `\n` line endings in the resulting file. This should probably just be an option with the default being to preserve the line ending format of the template file, but since this is being used to render files that should run on Linux and apparently incorrect line endings mess up the shebang reading and sh*t like that so I'm applying this "sh*t fix" for now. --- CHANGELOG.md | 11 +++++++++++ _sandbox_string.py | 2 +- _sandbox_template.txt | 4 +++- ccpstencil/__init__.py | 2 +- ccpstencil/renderer/_file.py | 4 +++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2020c2d..4ef81f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.8.0] - 2024-06-04 + +## Changed + +- `FileRenderer` (and thus `DirectoryRenderer`) now use `\n` line endings in the + resulting file. This should probably just be an option with the default being + to preserve the line ending format of the template file, but since this is + being used to render files that should run on Linux and apparently incorrect + line endings mess up the shebang reading and sh*t like that so I'm applying + this "sh*t fix" for now. + ## [0.7.0] - 2024-05-30 ## Added diff --git a/_sandbox_string.py b/_sandbox_string.py index a758584..a5f3a0b 100644 --- a/_sandbox_string.py +++ b/_sandbox_string.py @@ -12,7 +12,7 @@ def main(): # rnd = stencils.StringRenderer(ctx, tpl) # rnd = stencils.StdOutRenderer(ctx, tpl) - rnd = stencils.FileRenderer('./build/something/', ctx, tpl, overwrite=True) + rnd = stencils.FileRenderer('./build/something2/', ctx, tpl, overwrite=True) print(rnd.render()) diff --git a/_sandbox_template.txt b/_sandbox_template.txt index d856694..7ba791b 100644 --- a/_sandbox_template.txt +++ b/_sandbox_template.txt @@ -1,4 +1,6 @@ {% setfilename %} {{colors.favorite}}_file.txt {% endsetfilename %} -My name is {{name}} and I am {{age}} years old and my favorite color is NOT {{colors.weakness}} \ No newline at end of file +My name is {{name}} and +I am {{age}} years old and my +favorite color is NOT {{colors.weakness}} \ No newline at end of file diff --git a/ccpstencil/__init__.py b/ccpstencil/__init__.py index db1f83d..205cd83 100644 --- a/ccpstencil/__init__.py +++ b/ccpstencil/__init__.py @@ -1,4 +1,4 @@ -__version__ = '0.7.0' +__version__ = '0.8.0' __author__ = 'Thordur Matthiasson ' __license__ = 'MIT License' diff --git a/ccpstencil/renderer/_file.py b/ccpstencil/renderer/_file.py index 59f6428..3b3bdd0 100644 --- a/ccpstencil/renderer/_file.py +++ b/ccpstencil/renderer/_file.py @@ -13,8 +13,10 @@ class FileRenderer(StringRenderer): def __init__(self, output_path: Union[str, Path], context: Optional[IContext] = None, template: Optional[ITemplate] = None, overwrite: bool = True, + new_line_char: str = '\n', **kwargs): self._overwrite = overwrite + self._new_line_char = new_line_char super().__init__(context, template, **kwargs) is_dir = False log.debug(f'{output_path=}') @@ -46,7 +48,7 @@ def _output_rendered_results(self, rendered_string: str) -> str: f' disabled: {fout_path.absolute()}') fout_path.parent.mkdir(parents=True, exist_ok=True) - with open(fout_path, 'w') as fout: + with open(fout_path, 'w', newline=self._new_line_char) as fout: fout.write(results) return str(fout_path.absolute())