diff --git a/docs/cli.rst b/docs/cli.rst index 90b5c899..7af5a3ac 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -24,6 +24,13 @@ 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 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. + .. option:: --draft Only render news fragments to standard output. @@ -67,6 +74,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. 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/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. 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): """