Skip to content

Commit

Permalink
Add variable batou_generated_header to global template rendering co…
Browse files Browse the repository at this point in the history
…ntext
  • Loading branch information
elikoga committed Aug 13, 2024
1 parent ec76991 commit 4c9e380
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions src/batou/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/batou/tests/test_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 4c9e380

Please sign in to comment.