diff --git a/docs/configuration.rst b/docs/configuration.rst index c55299ba..5da44eed 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -135,6 +135,7 @@ Top level keys ``ignore`` A case-insensitive list of filenames in the news fragments directory to ignore. + Wildcard matching is supported via the `fnmatch `_ function. ``None`` by default. diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index c775d74e..9154f761 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -9,6 +9,7 @@ import textwrap from collections import defaultdict +from fnmatch import fnmatch from pathlib import Path from typing import Any, DefaultDict, Iterable, Iterator, Mapping, NamedTuple, Sequence @@ -149,7 +150,12 @@ def find_fragments( file_content = {} for basename in files: - if basename.lower() in ignored_files: + if any( + [ + fnmatch(basename.lower(), ignore_pattern) + for ignore_pattern in ignored_files + ] + ): continue issue, category, counter = parse_newfragment_basename( diff --git a/src/towncrier/newsfragments/644.feature.rst b/src/towncrier/newsfragments/644.feature.rst new file mode 100644 index 00000000..4c09a148 --- /dev/null +++ b/src/towncrier/newsfragments/644.feature.rst @@ -0,0 +1 @@ +Config `ignore` option now supports wildcard matching via `fnmatch `_. diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index f97fa91d..0092d495 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -1677,12 +1677,13 @@ def test_uncommitted_files(self, runner, commit): config=""" [tool.towncrier] package = "foo" - ignore = ["template.jinja", "CAPYBARAS.md"] + ignore = ["template.jinja", "CAPYBARAS.md", "seq_wildcard_[ab]"] """ ) def test_ignored_files(self, runner): """ When `ignore` is set in config, files with those names are ignored. + Configuration supports wildcard matching with `fnmatch`. """ with open("foo/newsfragments/123.feature", "w") as f: f.write("This has valid filename (control case)") @@ -1692,6 +1693,8 @@ def test_ignored_files(self, runner): f.write("This markdown file has been manually ignored") with open("foo/newsfragments/.gitignore", "w") as f: f.write("gitignore is automatically ignored") + with open("foo/newsfragments/seq_wildcard_a", "w") as f: + f.write("Manually ignored with [] wildcard") result = runner.invoke(_main, ["--draft"]) self.assertEqual(0, result.exit_code, result.output) diff --git a/src/towncrier/test/test_check.py b/src/towncrier/test/test_check.py index 7305b11d..baa33561 100644 --- a/src/towncrier/test/test_check.py +++ b/src/towncrier/test/test_check.py @@ -475,8 +475,12 @@ def test_in_different_dir_with_nondefault_newsfragments_directory(self, runner): def test_ignored_files(self, runner): """ When `ignore` is set in config, files with those names are ignored. + Configuration supports wildcard matching with `fnmatch`. """ - create_project("pyproject.toml", extra_config='ignore = ["template.jinja"]') + create_project( + "pyproject.toml", + extra_config='ignore = ["template.jinja", "star_wildcard*"]', + ) write( "foo/newsfragments/124.feature", @@ -484,6 +488,7 @@ def test_ignored_files(self, runner): ) write("foo/newsfragments/template.jinja", "This is manually ignored") write("foo/newsfragments/.gitignore", "gitignore is automatically ignored") + write("foo/newsfragments/star_wildcard_foo", "Manually ignored with * wildcard") commit("add stuff") result = runner.invoke(towncrier_check, ["--compare-with", "main"])