Repository: twisted/towncrier

Issue:
Ignore template only base on filename not an full path
              This is not ok.

We should extract the filename from the filepath.

_Originally posted by @adiroiban in https://github.com/twisted/towncrier/pull/633#discussion_r1698695121_
            

Discussion:

Patch:
diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py
index 4192942..d1f65f9 100644
--- a/src/towncrier/_builder.py
+++ b/src/towncrier/_builder.py
@@ -119,7 +119,7 @@ def find_fragments(
         # Template can be a tuple of (package_name, resource_name).
         #
         # See https://github.com/twisted/towncrier/issues/634
-        ignored_files.add(config.template)
+        ignored_files.add(os.path.basename(config.template))
     if config.ignore:
         ignored_files.update(filename.lower() for filename in config.ignore)
 
diff --git a/src/towncrier/newsfragments/638.bugfix b/src/towncrier/newsfragments/638.bugfix
new file mode 100644
index 0000000..540da13
--- /dev/null
+++ b/src/towncrier/newsfragments/638.bugfix
@@ -0,0 +1,1 @@
+The template file is now ignored based only on the file name.


Test patch:
diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py
index aa989fd..4556cca 100644
--- a/src/towncrier/test/test_build.py
+++ b/src/towncrier/test/test_build.py
@@ -1604,9 +1604,7 @@ class TestCli(TestCase):
         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"]
-        )
+        result = runner.invoke(_main, ["--draft"])
         self.assertEqual(0, result.exit_code, result.output)
 
     @with_project(
@@ -1625,9 +1623,7 @@ class TestCli(TestCase):
         with open("foo/newsfragments/feature.124", "w") as f:
             f.write("This has the issue and category the wrong way round")
 
-        result = runner.invoke(
-            _main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
-        )
+        result = runner.invoke(_main, ["--draft"])
         self.assertEqual(1, result.exit_code, result.output)
         self.assertIn("Invalid news fragment name: feature.124", result.output)
 
@@ -1635,24 +1631,37 @@ class TestCli(TestCase):
         config="""
         [tool.towncrier]
         package = "foo"
-        template = "foo/newsfragments/template.jinja"
+        template = "foo/newsfragments/template.j2"
+        ignore = ["placeholder-to-trigger-strict-checks.txt"]
         """
     )
-    def test_ignored_template_string(self, runner):
+    def test_ignore_template_filename(self, runner):
         """
-        Files used in `template` are automatically ignored.
+        The `template` filename is automatically ignored when it
+        is stored in the same path as the newsfragment files.
         """
         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("Template file should be automatically ignored")
-        with open("foo/newsfragments/.gitignore", "w") as f:
-            f.write("gitignore is automatically ignored")
+            f.write("Brand new thing.")
+        with open("foo/newsfragments/template.j2", "w") as f:
+            # Just a simple template to check that the file is rendered.
+            f.write(
+                """
+{% for section, _ in sections.items() %}
+{% for category, val in definitions.items() if category in sections[section]%}
+{{ definitions[category]['name'] }}
 
-        result = runner.invoke(
-            _main, ["--draft", "--date", "01-01-2001", "--version", "1.0.0"]
-        )
+{% for text, values in sections[section][category].items() %}
+- TEST {{ text }}
+{% endfor %}
+
+{% endfor %}
+{% endfor %}
+"""
+            )
+
+        result = runner.invoke(_main, ["--draft"])
         self.assertEqual(0, result.exit_code, result.output)
+        self.assertIn("- TEST Brand new thing.\n", result.output)
 
     @with_project()
     def test_no_ignore_configured(self, runner):