Skip to content
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
14 changes: 4 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@ changelog](https://rules-python.readthedocs.io/en/latest/changelog.html).
([#1975](https://github.com/bazel-contrib/rules_python/issues/1975))





{#v2-4-6}
## [2.4.6] - 2026-10-29

Expand Down Expand Up @@ -345,8 +342,6 @@ changelog](https://rules-python.readthedocs.io/en/latest/changelog.html).
([#4029](https://github.com/bazel-contrib/rules_python/issues/4029)).




{#v2-3-4}
## [2.3.4] - 2026-09-21

Expand Down Expand Up @@ -539,7 +534,6 @@ Work towards [#2787](https://github.com/bazel-contrib/rules_python/issues/2787)
and [#1975](https://github.com/bazel-contrib/rules_python/issues/1975).



{#v2-1-0}
## [2.1.0] - 2026-06-17

Expand Down Expand Up @@ -571,9 +565,9 @@ and [#1975](https://github.com/bazel-contrib/rules_python/issues/1975).
{#v2-1-0-fixed}
### Fixed
* (gazelle) `py_library` and `py_test` targets with missing source files can now be
removed by Gazelle ([#3375](https://github.com/bazel-contrib/rules_python/issues/3375)).
However `map_kind` and `alias_kind` will not be removed unless people are running a
gazelle version that includes
removed by Gazelle ([#3375](https://github.com/bazel-contrib/rules_python/issues/3375)).
However `map_kind` and `alias_kind` will not be removed unless people are running a
gazelle version that includes
[bazel-gazelle#2362](https://github.com/bazel-contrib/bazel-gazelle/pull/2362)
* (bootstrap) Fixed a potential race condition with symlink creation during
startup.
Expand Down Expand Up @@ -627,7 +621,7 @@ and [#1975](https://github.com/bazel-contrib/rules_python/issues/1975).
Fixes [#3296](https://github.com/bazel-contrib/rules_python/issues/3296).
* (gazelle) Support alias_kind directive.
Fixes [#3183](https://github.com/bazel-contrib/rules_python/issues/3183).
* (pypi) `package_metadata` support, fixes
* (pypi) `package_metadata` support, fixes
[#2054](https://github.com/bazel-contrib/rules_python/issues/2054).
* (coverage) Add support for python 3.14 and bump `coverage.py` to 7.10.7.

Expand Down
25 changes: 17 additions & 8 deletions dev/release/changelog_news.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import pathlib
import re

# The release blocks end with a newline; this adds the two blank lines that
# separate them from the next version.
_VERSION_SEPARATOR = "\n\n"


def _get_sub_category(content):
"""Extracts the sub-category in parentheses from the entry content."""
Expand Down Expand Up @@ -286,14 +290,19 @@ def _add_news_to_changelog(input_path, output_path, version, entries, release_da
header_str.rstrip() + "\n\nNo notable unreleased changes.\n"
)

# Replace in changelog_content
new_content = re.sub(
pattern,
r"\g<anchor>\n" + new_release_block.strip() + "\n",
changelog_content,
count=1,
flags=re.DOTALL,
# Replace in changelog_content. The match stops before the blank
# lines that separate the block from the next version, so normalize
# them instead of adding a newline on every merge.
new_content = (
changelog_content[: match.start()]
+ version_anchor
+ "\n"
+ new_release_block.strip()
+ "\n"
)
rest = changelog_content[match.end() :].lstrip()
if rest:
new_content += _VERSION_SEPARATOR + rest
output_path.write_text(new_content, encoding="utf-8")

else:
Expand All @@ -309,7 +318,7 @@ def _add_news_to_changelog(input_path, output_path, version, entries, release_da
new_content = (
changelog_content[:insertion_point]
+ new_release_block
+ "\n\n"
+ _VERSION_SEPARATOR
+ changelog_content[insertion_point:]
)
output_path.write_text(new_content, encoding="utf-8")
Expand Down
128 changes: 128 additions & 0 deletions tests/tools/private/release/changelog_news_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,134 @@ def test_update_changelog_merge_existing(tmp_path):
assert "Unreleased changes are tracked as individual files" in new_content


def test_update_changelog_repeated_merges_keep_blank_lines(tmp_path):
# Arrange
changelog = """# Changelog

{#unreleased}
## Unreleased

[unreleased]: https://github.com/bazel-contrib/rules_python/releases/tag/unreleased

{#v2-0-2}
## [2.0.2] - 2026-06-01

[2.0.2]: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.2

{#v2-0-2-fixed}
### Fixed
* (pypi) Old fix
"""
changelog_path = tmp_path / "CHANGELOG.md"
changelog_path.write_text(changelog)

news_dir = tmp_path / "news"
news_dir.mkdir()

# Act: every backport merges its news into the same version.
for i in range(3):
(news_dir / f"{i}.fixed.md").write_text(f"(pypi) Fix {i}")
changelog_news.update_changelog(
"2.0.3",
"2026-06-15",
changelog_path=changelog_path,
news_dir=news_dir,
)

# Assert
new_content = changelog_path.read_text()
expected = """{#v2-0-3-fixed}
### Fixed
* (pypi) Fix 0
* (pypi) Fix 1
* (pypi) Fix 2


{#v2-0-2}
"""
assert expected in new_content
assert new_content.endswith("* (pypi) Old fix\n")


def test_update_changelog_merge_last_block_with_backslashes(tmp_path):
# Arrange
changelog = """# Changelog

{#v2-0-3}
## [2.0.3] - 2026-06-15

[2.0.3]: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.3

{#v2-0-3-fixed}
### Fixed
* (pypi) Paths like `C:\\dir` work
"""
changelog_path = tmp_path / "CHANGELOG.md"
changelog_path.write_text(changelog)

news_dir = tmp_path / "news"
news_dir.mkdir()

# Act
for i in range(2):
(news_dir / f"{i}.fixed.md").write_text(f"(pypi) Regex `\\d{i}` works")
changelog_news.update_changelog(
"2.0.3",
"2026-06-15",
changelog_path=changelog_path,
news_dir=news_dir,
)

# Assert
new_content = changelog_path.read_text()
expected = """### Fixed
* (pypi) Paths like `C:\\dir` work
* (pypi) Regex `\\d0` works
* (pypi) Regex `\\d1` works
"""
assert new_content.endswith(expected)


def test_update_changelog_merge_normalizes_blank_lines(tmp_path):
# Arrange
changelog = """# Changelog

{#v2-0-3}
## [2.0.3] - 2026-06-15

[2.0.3]: https://github.com/bazel-contrib/rules_python/releases/tag/2.0.3

{#v2-0-3-fixed}
### Fixed
* (pypi) Fix 0





{#v2-0-2}
## [2.0.2] - 2026-06-01
"""
changelog_path = tmp_path / "CHANGELOG.md"
changelog_path.write_text(changelog)

news_dir = tmp_path / "news"
news_dir.mkdir()
(news_dir / "1.fixed.md").write_text("(pypi) Fix 1")

# Act
changelog_news.update_changelog(
"2.0.3",
"2026-06-15",
changelog_path=changelog_path,
news_dir=news_dir,
)

# Assert
new_content = changelog_path.read_text()
assert "* (pypi) Fix 1\n\n\n{#v2-0-2}\n" in new_content


def test_update_changelog_does_not_leak(tmp_path):
# Arrange
changelog = """# Changelog
Expand Down
Loading