Skip to content

Commit 8c1f333

Browse files
committed
Merge pull request #10580 from pradyunsg/better-towncrier-template
Improve our towncrier template, to do the right thing after releases
1 parent cc559ed commit 8c1f333

File tree

3 files changed

+41
-30
lines changed

3 files changed

+41
-30
lines changed

docs/html/news.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ Changelog
77
Major and minor releases of pip also include changes listed within
88
prior beta releases.
99

10-
.. towncrier-draft-entries:: |release|, unreleased as on
10+
.. towncrier-draft-entries:: Not yet released
1111

1212
.. pip-news-include:: ../../NEWS.rst

pyproject.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@ requires = ["setuptools", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.towncrier]
6+
# For finding the __version__
67
package = "pip"
78
package_dir = "src"
9+
# For writing into the correct file
810
filename = "NEWS.rst"
11+
# For finding the news fragments
912
directory = "news/"
10-
title_format = "{version} ({project_date})"
13+
14+
# For rendering properly for this project
1115
issue_format = "`#{issue} <https://github.com/pypa/pip/issues/{issue}>`_"
1216
template = "tools/news/template.rst"
17+
18+
# Grouping of entries, within our changelog
1319
type = [
1420
{ name = "Process", directory = "process", showcontent = true },
1521
{ name = "Deprecations and Removals", directory = "removal", showcontent = true },

tools/news/template.rst

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,46 @@
1-
{% set underline = "=" %}
1+
{# This is a heavily customised version of towncrier's default template. #}
22

3-
{{ underline * ((top_line)|length) }}
4-
{% for section in sections %}
5-
{% set underline = "-" %}
6-
{% if section %}
7-
{{ section }}
8-
{{ underline * section|length }}{% set underline = "~" %}
3+
{#-
4+
Only render if there's any changes to show.
95

10-
{% endif %}
11-
{% if sections[section] %}
12-
{% for category, val in definitions.items() if category in sections[section] and category != 'trivial' %}
6+
This serves as a compatibility "hack" since we render unreleased news entries
7+
in our changelog with ``sphinxcontrib.towncrier``; which triggers a render even
8+
when there's no entries to be rendered.
9+
#}
10+
{% if sections[''] %}
1311

14-
{{ definitions[category]['name'] }}
15-
{{ underline * definitions[category]['name']|length }}
12+
{#- Heading for individual version #}
13+
{{ versiondata.version }} ({{ versiondata.date }})
14+
{{ top_underline * ((versiondata.version + versiondata.date)|length + 3) }}
1615

17-
{% if definitions[category]['showcontent'] %}
18-
{% for text, values in sections[section][category]|dictsort(by='value') %}
19-
- {{ text }}{% if category != 'vendor' and category != 'process' %} ({{ values|sort|join(', ') }}){% endif %}
16+
{#
2017

21-
{% endfor %}
22-
{% else %}
23-
- {{ sections[section][category]['']|sort|join(', ') }}
18+
The following loop will run exactly once, with ``section_name == ""``.
2419

20+
This is due to the undocumented "sections" feature in towncrier.
21+
See https://github.com/twisted/towncrier/issues/61.
2522

26-
{% endif %}
27-
{% if sections[section][category]|length == 0 %}
23+
We don't use this feature, and this template doesn't render the section
24+
heading for that reason.
25+
#}
26+
{% for section_name, entries_by_type in sections.items() -%}
27+
{# Only show types with entries and ``showcontent = true``, using the order from pyproject.toml #}
28+
{% for type_ in definitions if (sections[section_name][type_] and definitions[type_]['showcontent']) %}
2829

29-
No significant changes.
30+
{# Heading for individual types #}
31+
{{ definitions[type_]['name'] }}
32+
{{ underlines[0] * definitions[type_]['name']|length }}
3033

31-
32-
{% else %}
33-
{% endif %}
34+
{# This is the loop that generates individual entries #}
35+
{% for message, issue_reference in sections[section_name][type_]|dictsort(by='value') %}
36+
- {{ message }}
37+
{%- if type_ not in ["vendor", "process"] %} ({{ issue_reference|sort|join(', ') }}){% endif %}
3438
{% endfor %}
35-
{% else %}
3639

40+
{% else %}
41+
{# We only have entries where the type has ``showcontent = true``. #}
3742
No significant changes.
3843

39-
40-
{% endif %}
41-
{% endfor %}
44+
{% endfor -%}
45+
{% endfor -%}
46+
{% endif -%}

0 commit comments

Comments
 (0)