Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically ignore template files #633

Merged
merged 11 commits into from
Jul 31, 2024
5 changes: 5 additions & 0 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ 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(str, config.template)
adiroiban marked this conversation as resolved.
Show resolved Hide resolved
# Template can be a tuple of (package_name, resource_name).
#
# See https://github.com/twisted/towncrier/issues/634
ignored_files.add(config.template)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ok.

We should extract the filename from the filepath.

if config.ignore:
ignored_files.update(filename.lower() for filename in config.ignore)

Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/632.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Automatically ignore template files
aviramha marked this conversation as resolved.
Show resolved Hide resolved
23 changes: 23 additions & 0 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,29 @@ 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 = "foo/newsfragments/template.jinja"
"""
)
def test_ignored_template_string(self, runner):
"""
Files used in `template` are automatically ignored.
aviramha marked this conversation as resolved.
Show resolved Hide resolved
"""
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")

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):
"""
Expand Down
Loading