From 36cb968dd840000a6f6870ba75ad6190e58d39f6 Mon Sep 17 00:00:00 2001 From: Aviram Hassan Date: Wed, 31 Jul 2024 10:31:39 +0000 Subject: [PATCH] automatically ignore template files --- src/towncrier/_builder.py | 2 ++ src/towncrier/test/test_build.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index 62a7d3f3..dabd64ad 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -115,6 +115,8 @@ def find_fragments( If strict, raise ClickException if any fragments have an invalid name. """ ignored_files = {".gitignore", ".keep", "readme", "readme.md", "readme.rst"} + if isinstance(config.template, str): + ignored_files.add(config.template) if config.ignore: ignored_files.update(filename.lower() for filename in config.ignore) diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index c14fd582..73ad69da 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -1631,6 +1631,30 @@ def test_invalid_fragment_name(self, runner): self.assertEqual(1, result.exit_code, result.output) self.assertIn("Invalid news fragment name: feature.124", result.output) + @with_project( + config=""" + [tool.towncrier] + package = "foo" + template = ["template.jinja"] + """ + ) + def test_ignored_template_string(self, runner): + """ + Files used in `template` are automatically ignored. + """ + with open("foo/newsfragments/123.feature", "w") as f: + f.write("This has valid filename (control case)") + with open("foo/newsfragments/template.jinja", "w") as f: + f.write("This template has been automatically ignored") + with open("foo/newsfragments/.gitignore", "w") as f: + f.write("gitignore is automatically ignored") + + result = runner.invoke( + _main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"] + ) + self.assertEqual(0, result.exit_code, result.output) + + @with_project() def test_no_ignore_configured(self, runner): """