diff --git a/CHANGES.md b/CHANGES.md index 38aef333..7f266378 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,9 @@ - Fix unsatisfied resource message if a host-specific resource is not satisfied. (#463) +- Adds variable `batou_generated_header` to global template rendering + context. This variable contains a comment block that signals that + the file content is generated by batou. (#356) ## 2.5.0b3 (2024-08-05) diff --git a/src/batou/component.py b/src/batou/component.py index 73ae7ccb..5cc0503c 100644 --- a/src/batou/component.py +++ b/src/batou/component.py @@ -16,6 +16,10 @@ from batou import DuplicateComponent, SilentConfigurationError, output from batou.utils import call_with_optional_args +batou_generated_header = """\ +# File is generated by batou. Don't edit manually. +""" + def platform(name, component): """Class decorator to register a component class as a platform-component @@ -945,6 +949,7 @@ def _template_args(self, component=None, **kw): host=component.host, environment=component.environment, component=component, + batou_generated_header=batou_generated_header, ) args.update(kw) return args diff --git a/src/batou/tests/test_component.py b/src/batou/tests/test_component.py index 23490586..a81ecc34 100644 --- a/src/batou/tests/test_component.py +++ b/src/batou/tests/test_component.py @@ -417,6 +417,14 @@ def test_templates(root): assert root.component.template("sample") == ("Hello localhost\n") +def test_template_batou_generated_header(root): + with open("sample", "w") as template: + template.write("Hello\n{{batou_generated_header}}") + assert root.component.template("sample") == ( + "Hello\n# File is generated by batou. Don't edit manually.\n\n" + ) + + def test_chdir_contextmanager_is_stackable(): outer = os.getcwd() inner1 = os.path.join(os.path.dirname(__file__), "fixture")