Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows tracking change log entries within pull requests. Below is the script used to convert the old semi-dynamic changelog format into a static one: #! /usr/bin/env python3 import subprocess from pathlib import Path from re import sub as _re_replace from dateutil.parser import parse as parse_timestamp def _get_scm_timestamp_for(committish): """Retrieve the tag date from SCM.""" try: ts = subprocess.check_output( ('git', 'log', '-1', '--format=%aI', committish), stderr=subprocess.DEVNULL, text=True, ).strip() except subprocess.SubprocessError: raise ValueError( f'There is no `{committish}` in Git', ) from None return parse_timestamp(ts) def _retrieve_release_date(version_tag): try: version_date = _get_scm_timestamp_for(version_tag) except (ValueError, RuntimeError): return 'no Git tag matched' else: return f'{version_date:%Y-%m-%d}' changes_rst_path = Path('CHANGES.rst') changes_rst_txt = changes_rst_path.read_text() def _replace_version(ver_match_obj) -> str: version_str = ver_match_obj.group('version_string') prefixed_version_str = f'v{version_str !s}' release_date = _retrieve_release_date(prefixed_version_str) return f'{prefixed_version_str !s}\n{"=" * len(prefixed_version_str)}\n\n*({release_date !s})*' replaced_changes_rst_txt = _re_replace(r'.. scm-version-title:: v(?P<version_string>\d+.\d+.\d+)', _replace_version, changes_rst_txt) changes_rst_path.write_text(replaced_changes_rst_txt)
- Loading branch information