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

Make consistent the expectation around non-existent fragments directory #557

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
By default, the processed news fragments are removed using ``git``, which will
also remove the fragments directory if now empty.
By default, the processed news fragments are removed using ``git rm``.

I don't think that towncrier (or git) explicitly removes the empty dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tested this expectation in one of my projects. For example, you can checkout /jaraco/skeleton, which currently has one fragment, and run towncrier build 0.0.0, and it will remove the newsfragmenta dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's where I did just that yesterday:

 @ work-on skeleton
 skeleton main @ towncrier build --version 0.0.0
Loading template...
Finding news fragments...
Rendering news fragments...
Writing to newsfile...
Staging newsfile...
I want to remove the following files:
/Users/jaraco/code/jaraco/skeleton/newsfragments/+drop-py37.feature.rst
Is it okay if I remove those files? [Y/n]: y
Removing news fragments...
Done!
 skeleton main @ cat NEWS.rst
0.0.0
=====

Features
--------

- Require Python 3.8 or later.
 skeleton main @ towncrier build --version 0.0.1
Loading template...
Finding news fragments...
Failed to list the news fragment files.
FileNotFoundError: [Errno 2] No such file or directory: '/Users/jaraco/code/jaraco/skeleton/newsfragments'

 skeleton main @ mkdir newsfragments
 skeleton main @ towncrier build --version 0.0.1
Loading template...
Finding news fragments...
Rendering news fragments...
Writing to newsfile...
Staging newsfile...
No news fragments to remove. Skipping!
Done!


.. 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)
Copy link
Member

Choose a reason for hiding this comment

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

Thanks. It looks like this was a bug.

The test docstring states that it is expected to handle it as no changes, but in fact it was failing :)


def test_no_newsfragments_draft(self):
"""
Expand Down
Loading