From 7494cb47d658fca200b8514d65529d867cb6d13d Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 23 Oct 2023 20:56:35 -0400 Subject: [PATCH 1/3] Add some documentation explaining the current behavior around the fragments directory. --- docs/cli.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/cli.rst b/docs/cli.rst index 90b5c899..50c6dd58 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -24,6 +24,12 @@ The following options can be passed to all of the commands that explained below: Build the combined news file from news fragments. ``build`` is also assumed if no command is passed. +If there are no news fragments (including an empty fragments directory), a +notice of "no significant changes" will be added to the news file. + +By default, the processed news fragments are removed using ``git``, which will +also remove the fragments directory if now empty. + .. option:: --draft Only render news fragments to standard output. @@ -67,6 +73,8 @@ Create a news fragment in the directory that ``towncrier`` is configured to look ``towncrier create`` will enforce that the passed type (e.g. ``bugfix``) is valid. +If the fragments directory does not exist, it will be created. + If the filename exists already, ``towncrier create`` will add (and then increment) a number after the fragment type until it finds a filename that does not exist yet. In the above example, it will generate ``123.bugfix.1.rst`` if ``123.bugfix.rst`` already exists. From 857df1052e62035dbb1b7a713cc507625b2afafc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 23 Oct 2023 20:59:02 -0400 Subject: [PATCH 2/3] Reflect expectation that a non-existent directory is honored and treated like an empty directory. Closes #538. --- docs/cli.rst | 5 +++-- src/towncrier/_builder.py | 10 ++-------- src/towncrier/test/test_build.py | 4 ++-- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/docs/cli.rst b/docs/cli.rst index 50c6dd58..7af5a3ac 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -24,8 +24,9 @@ The following options can be passed to all of the commands that explained below: Build the combined news file from news fragments. ``build`` is also assumed if no command is passed. -If there are no news fragments (including an empty fragments directory), a -notice of "no significant changes" will be added to the news file. +If there are no news fragments (including an empty fragments directory or a +non-existent directory), a notice of "no significant changes" will be added to +the news file. By default, the processed news fragments are removed using ``git``, which will also remove the fragments directory if now empty. diff --git a/src/towncrier/_builder.py b/src/towncrier/_builder.py index 6f8f166b..3f72f1fa 100644 --- a/src/towncrier/_builder.py +++ b/src/towncrier/_builder.py @@ -6,15 +6,12 @@ import os import textwrap -import traceback from collections import defaultdict from typing import Any, DefaultDict, Iterable, Iterator, Mapping, Sequence from jinja2 import Template -from ._settings import ConfigError - def strip_if_integer_string(s: str) -> str: try: @@ -102,11 +99,8 @@ def find_fragments( try: files = os.listdir(section_dir) - except FileNotFoundError as e: - message = "Failed to list the news fragment files.\n{}".format( - "".join(traceback.format_exception_only(type(e), e)), - ) - raise ConfigError(message) + except FileNotFoundError: + files = [] file_content = {} diff --git a/src/towncrier/test/test_build.py b/src/towncrier/test/test_build.py index f15cd9ab..780a3c83 100644 --- a/src/towncrier/test/test_build.py +++ b/src/towncrier/test/test_build.py @@ -182,8 +182,8 @@ def test_no_newsfragment_directory(self, runner): result = runner.invoke(_main, ["--draft", "--date", "01-01-2001"]) - self.assertEqual(1, result.exit_code, result.output) - self.assertIn("Failed to list the news fragment files.\n", result.output) + self.assertEqual(0, result.exit_code) + self.assertIn("No significant changes.\n", result.output) def test_no_newsfragments_draft(self): """ From c36652ffa658175ad2a307a9cfb319330bec8356 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Mon, 23 Oct 2023 21:19:11 -0400 Subject: [PATCH 3/3] Add news fragment. --- src/towncrier/newsfragments/538.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/towncrier/newsfragments/538.bugfix diff --git a/src/towncrier/newsfragments/538.bugfix b/src/towncrier/newsfragments/538.bugfix new file mode 100644 index 00000000..3a6fbf34 --- /dev/null +++ b/src/towncrier/newsfragments/538.bugfix @@ -0,0 +1 @@ +``build`` now treats a missing fragments directory the same as an empty one, consistent with other operations.