repomatic.changelog module¶
Changelog parsing, updating, and release lifecycle management.
This module is the single source of truth for parsing and rewriting the changelog. It handles two phases of the release cycle:
Post-release (unfreeze) — Changelog.update():
Decomposes the latest release section via Changelog.decompose_version(),
transforms the elements into an unreleased entry (date → unreleased,
comparison URL → ...main, body → development warning), renders via the
release-notes template, and prepends the result to the changelog.
Release preparation (freeze) — Changelog.freeze():
Decomposes the current unreleased section, sets the release date, freezes
the comparison URL to ...vX.Y.Z, clears the development warning,
renders via the release-notes template, and replaces the section
in place.
Both operations follow the same decompose → modify → render → replace
pattern, with the release-notes.md template as the single source of
truth for section layout. Both are idempotent: re-running them produces
the same result. This is critical for CI workflows that may be retried.
Note
This is a custom implementation. After evaluating all major alternatives — towncrier, commitizen, python-semantic-release, generate-changelog, release-please, scriv, and git-changelog (see issue #94) — none were found to cover even half of the requirements.
Why not use an off-the-shelf tool?¶
Existing tools fall into two camps, neither of which fits:
Commit-driven tools (python-semantic-release, commitizen, generate-changelog, release-please) auto-generate changelogs from Git history. This conflicts with the project’s philosophy of hand-curated changelogs: entries are written for users, consolidated by hand, and summarize only changes worth knowing about. Auto-generated logs from developer commits are too noisy and don’t account for back-and-forth during development.
Fragment-driven tools (towncrier, scriv) avoid merge conflicts by using per-change files, but handle none of the release orchestration: comparison URL management, GFM warning lifecycle, workflow action reference freezing, or the two-commit freeze/unfreeze release cycle. The multiplication of files across the repo adds complexity, and there is no 1:1 mapping between fragments and changelog entries.
Specific gaps across all evaluated tools:
No comparison URL management. None generate GitHub
v1.0.0...v1.1.0diff links, or update them from...mainto...vX.Y.Zat release time.No unreleased section lifecycle. None manage the
[!WARNING]GFM alert warning that the version is under active development, inserting it post-release and removing it at release time.No workflow action reference freezing. None handle the freeze/unfreeze cycle for
@main↔@vX.Y.Zreferences in workflow files.No two-commit release workflow. None support the freeze commit (
[changelog] Release vX.Y.Z) plus unfreeze commit ([changelog] Post-release bump) pattern thatchangelog.yamluses.No citation file integration. None update
citation.cffrelease dates.No version bump eligibility checks. None prevent double version increments by comparing the current version against the latest Git tag with a commit-message fallback.
The custom implementation in this module is tightly integrated with the release workflow. Adopting any external tool would require keeping most of this code and adding a new dependency — more complexity, not less.
- repomatic.changelog.resolved_changelog_path(config)[source]¶
Absolute path of the configured changelog.
The one derivation of
[tool.repomatic] changelog.locationinto a filesystem path, so every consumer (the CLI commands, the release freeze, the metadata singleton, the setup guide) resolves the same file the same way.- Return type:
- repomatic.changelog.load_changelog_repo(config)[source]¶
Load the configured changelog and read the repository URL out of it.
The shared preamble of the two release-notes syncers, which both need the changelog’s path (to read sections from) and the repository it belongs to (to address the GitHub API with). The URL comes from the changelog’s own comparison links rather than from the git remote, so a project whose changelog points elsewhere stays authoritative.
- repomatic.changelog.AVAILABLE_VERB = 'is available on'¶
Verb phrase for versions present on a platform.
- repomatic.changelog.CHANGELOG_HEADER = '# Changelog\n'¶
Default changelog header for empty changelogs.
- repomatic.changelog.FIRST_AVAILABLE_VERB = 'is the *first version* available on'¶
Verb phrase for the inaugural release on a platform.
- repomatic.changelog.GITHUB_LABEL = '🐙 GitHub'¶
Display label for GitHub releases in admonitions.
- repomatic.changelog.GITHUB_RELEASE_URL = '{repo_url}/releases/tag/v{version}'¶
GitHub release page URL for a specific version.
- repomatic.changelog.NOT_AVAILABLE_VERB = 'is **not available** on'¶
Verb phrase for versions missing from a platform.
- repomatic.changelog.PYPI_LABEL = '🐍 PyPI'¶
Display label for PyPI in admonitions.
- repomatic.changelog.SECTION_START = '##'¶
Markdown heading level for changelog version sections.
- repomatic.changelog.YANKED_DEDUP_MARKER = 'yanked from PyPI'¶
Dedup marker for the yanked admonition to prevent duplicate insertion.
- repomatic.changelog.RELEASE_VERSION_TOKEN = '\\d+\\.\\d+\\.\\d+'¶
Regex fragment for a final release version, like
1.2.3.The strict half of the version vocabulary: it deliberately rejects the
.devNsuffixVERSION_TOKENaccepts, because a changelog documents only final releases. Anything keyed off a published version (a dated heading, a comparison URL) uses this one.
- repomatic.changelog.VERSION_TOKEN = '\\d+\\.\\d+\\.\\d+(?:\\.\\w+)?'¶
Regex fragment for any version a
##heading may carry.Widens
RELEASE_VERSION_TOKENwith the trailing.devNa development section carries between releases. Anything enumerating or locating headings uses this one, so an unreleased section is never invisible to a scan that has to account for it.
- repomatic.changelog.GFM_ALERT_RE = re.compile('(?:^>.*$\\n?)+', re.MULTILINE)¶
A GFM alert block: consecutive lines starting with
>.The shape every changelog admonition takes (the development warning, the PyPI availability note, a yanked caution), matched wherever a section’s blocks are inventoried.
- repomatic.changelog.VERSION_COMPARE_PATTERN = re.compile('v\\d+\\.\\d+\\.\\d+\\.\\.\\.v\\d+\\.\\d+\\.\\d+')¶
Pattern matching GitHub comparison URLs like
v1.0.0...v1.0.1.
- repomatic.changelog.RELEASED_VERSION_PATTERN = re.compile('^##\\s*\\[`?(?P<version>\\d+\\.\\d+\\.\\d+)`?\\s+\\((?P<date>\\d{4}-\\d{2}-\\d{2})\\)\\]', re.MULTILINE)¶
Pattern matching released version headings with dates.
Captures version and date from headings like
## [`5.9.1` (2026-02-14)](...). Skips unreleased versions which use(unreleased)instead of a date. Backticks around the version are optional.
- repomatic.changelog.HEADING_PARTS_PATTERN = re.compile('^##\\s*\\[`?(?P<version>\\d+\\.\\d+\\.\\d+(?:\\.\\w+)?)`?\\s+\\((?P<date>[^)]+)\\)\\]\\((?P<url>[^)]+)\\)', re.MULTILINE)¶
Pattern extracting version, date/label, and URL from a heading.
Used by
Changelog.decompose_version()to populate the heading fields ofVersionElements.
- repomatic.changelog.TAG_PREFIXED_HEADING_RE = re.compile('^(?P<prefix>##\\s*\\[`?)v(?P<version>\\d+\\.\\d+\\.\\d+(?:\\.\\w+)?)\\b', re.MULTILINE)¶
A
##heading naming its version with thevof a git tag.No scan reads such a heading:
VERSION_TOKENopens on a digit, so the section stays invisible to every check, and its release goes unverified. The prefix belongs to the tag; a heading names the package version, bare.
- class repomatic.changelog.VersionElements(compare_url='', date='', version='', availability_admonition='', changes='', development_warning='', editorial_admonition='', yanked_admonition='')[source]¶
Bases:
objectDiscrete building blocks of a changelog version section.
Each field is a pre-formatted markdown block (or empty string when absent). Templates compose these elements into the final section layout. Empty variables produce empty strings, which
render_template’s 3+ newline collapsing handles gracefully.Heading fields (
compare_url,date,version) are populated byChangelog.decompose_version()and used by therelease-notestemplate to render the##heading line. Body fields are unchanged.- editorial_admonition: str = ''¶
Hand-written GFM alert blocks not matching auto-generated patterns.
Multiple blocks are joined with double newlines.
- class repomatic.changelog.Changelog(initial_changelog=None, current_version=None)[source]¶
Bases:
objectHelpers to manipulate changelog files written in Markdown.
Every lookup of a section goes through an index of the sections, built in one scan of
contentand dropped whenever the content changes. The lint loop reads each section several times: a scan of the whole changelog per read would make it quadratic in the number of releases.- update(default_branch='main')[source]¶
Add a new unreleased entry at the top of the changelog.
Decomposes the current version section, transforms it into an unreleased entry (date set to
unreleased, comparison URL retargeted to the default branch, body replaced with the development warning), and prepends it to the changelog.Idempotent: the content stays unchanged when an unreleased entry already exists, and when there is no current version or no section to clone.
- Parameters:
default_branch (
str) – Branch name for the comparison URL. Must match whatfreeze()is later given, since the two halves of a release cycle retarget the same URL in opposite directions: a mismatch leaves the released section pointing at a branch that does not exist.- Return type:
- Returns:
Trueif an entry was added tocontent.
- freeze(release_date=None, default_branch='main')[source]¶
Freeze the current unreleased section for release.
Decomposes the current version section, sets the release date, freezes the comparison URL to the release tag, clears the development warning, and re-renders via the
release-notestemplate.Returns
Falsefor three different situations, only one of which is benign: an already-frozen section (idempotent no-op), no version to freeze, and a version whose section is missing. The last one is what a release would otherwise ship an(unreleased)heading over, so it is logged as a warning rather than left to look like the no-op.
- classmethod freeze_file(path, version, release_date=None, default_branch='main')[source]¶
Freeze a changelog file in place.
Reads the file, applies all freeze operations via
freeze(), and writes the result back.
- extract_repo_url()[source]¶
Extract the repository URL from changelog comparison links.
Parses the first
## `... <<repo_url>/compare/...>`_heading and returns the base repository URL (e.g.https://github.com/user/repo).- Return type:
- Returns:
The repository URL, or empty string if not found.
- extract_all_releases()[source]¶
Extract all released versions and their dates from the changelog.
Scans for headings matching
## `X.Y.Z (YYYY-MM-DD) <...>`_. Unreleased versions (with(unreleased)) are skipped.
- extract_all_version_headings()[source]¶
Extract all version strings from
##headings.Includes both released and unreleased versions, so the caller can avoid false-positive orphan detection for the current development version.
- strip_tag_prefixes()[source]¶
Drop the
vtag prefix off every##heading carrying one.The comparison URL of the heading keeps its
v: that one names a tag.- Return type:
- Returns:
The number of headings rewritten.
- insert_version_section(version, date, repo_url, all_versions)[source]¶
Insert a placeholder section for a missing version.
The section is placed at the correct position in descending version order. The comparison URL points from the next-lower version to this one. After insertion, the next-higher version’s comparison URL base is updated to reference this version, keeping the timeline coherent.
Idempotent: returns False if the version heading already exists.
- Parameters:
- Return type:
- Returns:
True if the content was modified.
- update_comparison_base(version, new_base)[source]¶
Replace the base version in a version heading’s comparison URL.
Changes
compare/vOLD...vX.Y.Ztocompare/vNEW...vX.Y.Zin the heading for the given version.
- decompose_version(version)[source]¶
Decompose a version section into discrete elements.
Parses both the heading (version, date, URL) and the body (admonitions, changes).
Classifies each GFM alert block (consecutive
>lines) as one of the auto-generated element types. Everything not classified as auto-generated is preserved aschanges.The decomposition is cached until
contentchanges. Each call returns its own copy, which the caller is free to modify.- Parameters:
version (
str) – Version string (like1.2.3).- Return type:
- Returns:
A
VersionElementswith each field populated.
- repomatic.changelog.availability_admonition(version, *, pypi_url='', github_url='', first_on_pypi=False, first_on_github=False, missing_pypi=False, missing_github=False)[source]¶
Render the availability admonitions of a release section.
The one renderer of
VersionElements.availability_admonition. Two writers share it, so a release reads the same in both: lint-changelog –fix writes it into the changelog, and the draft GitHub release body bakes it in before that fix runs.A
> [!NOTE]links the platforms carrying the version. It uses the first version wording when the version is the first one on every platform it links. A> [!WARNING]names the platforms missing the version. Both blocks appear when a version is on one platform and missing from the other.- Parameters:
version (
str) – Version string (like1.2.3).pypi_url (
str) – PyPI page of the version, empty to leave PyPI out of the note.github_url (
str) – GitHub release page of the version, empty to leave GitHub out of the note.first_on_pypi (
bool) – Whether the version is the first one on PyPI.first_on_github (
bool) – Whether the version is the first GitHub release.missing_pypi (
bool) – Whether the version is missing from PyPI.missing_github (
bool) – Whether the version is missing from GitHub.
- Return type:
- Returns:
The admonition blocks, separated by a blank line. Empty when the version is neither linked nor missing anywhere.