Skip to content

Commit

Permalink
Make consistent the expectation around non-existent fragments directo…
Browse files Browse the repository at this point in the history
…ry (#557)

* Add some documentation explaining the current behavior around the fragments directory.

* Reflect expectation that a non-existent directory is honored and treated like an empty directory. Closes #538.

* Add news fragment.
  • Loading branch information
jaraco authored Oct 24, 2023
1 parent f6809f0 commit e4b892f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
9 changes: 9 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
10 changes: 2 additions & 8 deletions src/towncrier/_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 = {}

Expand Down
1 change: 1 addition & 0 deletions src/towncrier/newsfragments/538.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
``build`` now treats a missing fragments directory the same as an empty one, consistent with other operations.
4 changes: 2 additions & 2 deletions src/towncrier/test/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit e4b892f

Please sign in to comment.