Skip to content

Commit d3748f1

Browse files
committed
feat: make disclaimer optional and include informative comment to markdown template (#145)
1 parent 8636fc8 commit d3748f1

File tree

4 files changed

+54
-1
lines changed

4 files changed

+54
-1
lines changed

schemas/corsair-build-schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@
7474
"title": "Print Conventions",
7575
"type": "boolean"
7676
},
77+
"print_disclaimer": {
78+
"default": true,
79+
"description": "Enable generating disclaimer with version at the beginning of the file.",
80+
"title": "Print Disclaimer",
81+
"type": "boolean"
82+
},
7783
"wavedrom": {
7884
"$ref": "#/$defs/corsair___generators__wavedrom__WaveDromGenerator__Config",
7985
"default": {

src/corsair/_generators/markdown.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class Config(GeneratorConfig):
3939
print_conventions: bool = True
4040
"""Enable generating table with register access modes explained."""
4141

42+
print_disclaimer: bool = True
43+
"""Enable generating disclaimer with version at the beginning of the file."""
44+
4245
wavedrom: WaveDromGenerator.Config = WaveDromGenerator.Config()
4346
"""Configuration for the WaveDrom generator."""
4447

src/corsair/_templates/regmap.md.j2

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717
{% set tmp = namespace() %}
1818

1919
{#- TEMPLATE #}
20+
[//]: # (DO NOT EDIT THIS AUTOGENERATED FILE. ALL CHANGES WILL BE LOST.)
21+
2022
# {{ cfg.title }}
2123

22-
Created with [Corsair](https://github.com/esynr3z/corsair) v{{ version }}.
24+
{% if cfg.print_disclaimer %}
25+
Generated by [Corsair](https://github.com/esynr3z/corsair) v{{ version }}.
26+
{% endif %}
2327

2428
{% if cfg.print_conventions %}
2529
## Conventions

tests/generators/test_markdown.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,46 @@ def test_wavedrom_dump_json(tmp_path: Path, simple_regmap: csr.Map) -> None:
239239
assert {f for f in expected_data_dir.iterdir() if f.suffix == ".json"} == expected_json_files
240240

241241

242+
def test_autogenerated_comment_present(tmp_path: Path, simple_regmap: csr.Map) -> None:
243+
"""Test that the autogenerated comment is present in the output file."""
244+
config = csr.MarkdownGenerator.Config()
245+
gen = csr.MarkdownGenerator(
246+
label="test_md_gen_autogen_comment", register_map=simple_regmap, config=config, output_dir=tmp_path
247+
)
248+
generated_files = list(gen())
249+
250+
assert len(generated_files) == 1
251+
output_file = generated_files[0]
252+
assert output_file.is_file()
253+
254+
content = output_file.read_text()
255+
assert "[//]: # (DO NOT EDIT THIS AUTOGENERATED FILE. ALL CHANGES WILL BE LOST.)" in content
256+
257+
258+
def test_print_disclaimer_true(tmp_path: Path, simple_regmap: csr.Map) -> None:
259+
"""Test that disclaimer is printed when print_disclaimer is True."""
260+
config = csr.MarkdownGenerator.Config(print_disclaimer=True)
261+
gen = csr.MarkdownGenerator(
262+
label="test_md_gen_disclaimer_true", register_map=simple_regmap, config=config, output_dir=tmp_path
263+
)
264+
generated_files = list(gen())
265+
output_file = generated_files[0]
266+
content = output_file.read_text()
267+
assert "Generated by [Corsair]" in content
268+
269+
270+
def test_print_disclaimer_false(tmp_path: Path, simple_regmap: csr.Map) -> None:
271+
"""Test that disclaimer is not printed when print_disclaimer is False."""
272+
config = csr.MarkdownGenerator.Config(print_disclaimer=False)
273+
gen = csr.MarkdownGenerator(
274+
label="test_md_gen_disclaimer_false", register_map=simple_regmap, config=config, output_dir=tmp_path
275+
)
276+
generated_files = list(gen())
277+
output_file = generated_files[0]
278+
content = output_file.read_text()
279+
assert "Generated by [Corsair]" not in content
280+
281+
242282
def test_custom_template_and_extra_param(tmp_path: Path, simple_regmap: csr.Map, custom_template: Path) -> None:
243283
"""Test generation with a custom template and extra config parameters."""
244284
template_file = custom_template

0 commit comments

Comments
 (0)