Skip to content

Commit b09904d

Browse files
committed
Show pending newsfragments in documentation previews
sphinxcontrib-towncrier renders the newsfragments that have not been released yet at the top of the changelog, so that documentation previews built from pull requests include their entries. The title is now rendered by a custom towncrier template instead of title_format, so that the draft gets a plain "Unreleased" heading while releases keep their linked heading, unchanged.
1 parent b12acf5 commit b09904d

5 files changed

Lines changed: 74 additions & 1 deletion

File tree

docs/changelog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Change Log
22
==========
33

4+
.. towncrier-draft-entries::
5+
6+
Unreleased
7+
48
.. towncrier release notes start
59
610
`2.0.0 <https://github.com/python-astrodynamics/spacetrack/releases/tag/2.0.0>`_ - 2026-08-10

docs/conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import re
99
from importlib.metadata import distribution
10+
from pathlib import Path
1011

1112
from parver import Version
1213

@@ -44,8 +45,14 @@
4445
"sphinx.ext.mathjax",
4546
"sphinx.ext.napoleon",
4647
"sphinx.ext.viewcode",
48+
"sphinxcontrib.towncrier.ext",
4749
]
4850

51+
# Render pending newsfragments at the top of the changelog, so that previews
52+
# built from pull requests show their entries.
53+
towncrier_draft_include_empty = False
54+
towncrier_draft_working_directory = str(Path(__file__).resolve().parent.parent)
55+
4956
# List of patterns, relative to source directory, that match files and
5057
# directories to ignore when looking for source files.
5158
# This pattern also affects html_static_path and html_extra_path.

newsfragments/template.rst.jinja

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{% if render_title %}
2+
{% if versiondata.version == "Unreleased" %}
3+
Unreleased
4+
{{ top_underline * 10 }}
5+
{% else %}
6+
{% set title = "`" ~ versiondata.version ~ " <https://github.com/python-astrodynamics/spacetrack/releases/tag/" ~ versiondata.version ~ ">`_ - " ~ versiondata.date %}
7+
{{ title }}
8+
{{ top_underline * title|length }}
9+
{% endif %}
10+
{% endif %}
11+
{% for section, _ in sections.items() %}
12+
{% set underline = underlines[0] %}{% if section %}{{section}}
13+
{{ underline * section|length }}{% set underline = underlines[1] %}
14+
15+
{% endif %}
16+
17+
{% if sections[section] %}
18+
{% for category, val in definitions.items() if category in sections[section]%}
19+
{{ definitions[category]['name'] }}
20+
{{ underline * definitions[category]['name']|length }}
21+
22+
{% for text, values in sections[section][category].items() %}
23+
- {% if text %}{{ text }}{% if values %} ({{ values|join(', ') }}){% endif %}{% else %}{{ values|join(', ') }}{% endif %}
24+
25+
{% endfor %}
26+
27+
{% if sections[section][category]|length == 0 %}
28+
No significant changes.
29+
30+
{% else %}
31+
{% endif %}
32+
33+
{% endfor %}
34+
{% else %}
35+
No significant changes.
36+
37+
38+
{% endif %}
39+
{% endfor %}

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ docs = [
5858
"furo>=2024.8.6",
5959
"parver>=0.5",
6060
"sphinx>=7.4.7",
61+
"sphinxcontrib-towncrier>=0.5.0a0",
6162
]
6263
docstest = [
6364
{ include-group = "docs" },
@@ -116,8 +117,9 @@ ignore = ["D001"]
116117
[tool.towncrier]
117118
directory = "newsfragments"
118119
filename = "docs/changelog.rst"
120+
template = "newsfragments/template.rst.jinja"
119121
issue_format = "`#{issue} <https://github.com/python-astrodynamics/spacetrack/issues/{issue}>`_"
120-
title_format = "`{version} <https://github.com/python-astrodynamics/spacetrack/releases/tag/{version}>`_ - {project_date}"
122+
title_format = ""
121123
underlines = ["-", "~"]
122124

123125
[[tool.towncrier.type]]

uv.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)