From d23257a088818007a9d00fa1c6af5863261aacad Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:09:48 +0100 Subject: [PATCH 1/3] Move 'blurb release' to ``blurb._release`` --- src/blurb/_cli.py | 4 +-- src/blurb/_release.py | 70 +++++++++++++++++++++++++++++++++++++++++++ src/blurb/blurb.py | 68 +---------------------------------------- tests/test_blurb.py | 5 ---- tests/test_release.py | 8 +++++ 5 files changed, 81 insertions(+), 74 deletions(-) create mode 100644 src/blurb/_release.py create mode 100644 tests/test_release.py diff --git a/src/blurb/_cli.py b/src/blurb/_cli.py index b61c0a8..ca58214 100644 --- a/src/blurb/_cli.py +++ b/src/blurb/_cli.py @@ -5,7 +5,7 @@ import re import sys -import blurb +import blurb.blurb TYPE_CHECKING = False if TYPE_CHECKING: @@ -298,5 +298,5 @@ def test_first_line(filename, test): break - blurb.root = path + blurb.blurb.root = path return path diff --git a/src/blurb/_release.py b/src/blurb/_release.py new file mode 100644 index 0000000..8128a40 --- /dev/null +++ b/src/blurb/_release.py @@ -0,0 +1,70 @@ +from __future__ import annotations + +import os +import time + +import blurb.blurb +from blurb._cli import error, subcommand +from blurb.blurb import (Blurbs, flush_git_add_files, flush_git_rm_files, + git_rm_files, git_add_files, glob_blurbs, nonceify) + + +@subcommand +def release(version: str) -> None: + """Move all new blurbs to a single blurb file for the release. + + This is used by the release manager when cutting a new release. + """ + if version == '.': + # harvest version number from dirname of repo + # I remind you, we're in the Misc subdir right now + version = os.path.basename(blurb.blurb.root) + + existing_filenames = glob_blurbs(version) + if existing_filenames: + error("Sorry, can't handle appending 'next' files to an existing version (yet).") + + output = f'Misc/NEWS.d/{version}.rst' + filenames = glob_blurbs('next') + blurbs = Blurbs() + date = current_date() + + if not filenames: + print(f'No blurbs found. Setting {version} as having no changes.') + body = f'There were no new changes in version {version}.\n' + metadata = {'no changes': 'True', 'gh-issue': '0', 'section': 'Library', 'date': date, 'nonce': nonceify(body)} + blurbs.append((metadata, body)) + else: + count = len(filenames) + print(f'Merging {count} blurbs to "{output}".') + + for filename in filenames: + if not filename.endswith('.rst'): + continue + blurbs.load_next(filename) + + metadata = blurbs[0][0] + + metadata['release date'] = date + print('Saving.') + + blurbs.save(output) + git_add_files.append(output) + flush_git_add_files() + + how_many = len(filenames) + print(f"Removing {how_many} 'next' files from git.") + git_rm_files.extend(filenames) + flush_git_rm_files() + + # sanity check: ensuring that saving/reloading the merged blurb file works. + blurbs2 = Blurbs() + blurbs2.load(output) + assert blurbs2 == blurbs, f"Reloading {output} isn't reproducible?!" + + print() + print('Ready for commit.') + + +def current_date() -> str: + return time.strftime('%Y-%m-%d', time.localtime()) diff --git a/src/blurb/blurb.py b/src/blurb/blurb.py index dbbdb64..803835d 100755 --- a/src/blurb/blurb.py +++ b/src/blurb/blurb.py @@ -39,7 +39,6 @@ # # automatic git adds and removes -import atexit import base64 import builtins import glob @@ -49,18 +48,16 @@ import os from pathlib import Path import re -import shlex import shutil import subprocess import sys -import tempfile import textwrap import time from blurb._cli import main, subcommand from blurb._template import ( next_filename_unsanitize_sections, sanitize_section, - sanitize_section_legacy, sections, template, unsanitize_section, + sanitize_section_legacy, sections, unsanitize_section, ) root = None # Set by chdir_to_repo_root() @@ -156,10 +153,6 @@ def textwrap_body(body, *, subsequent_indent=''): text += "\n" return text - -def current_date(): - return time.strftime("%Y-%m-%d", time.localtime()) - def sortable_datetime(): return time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime()) @@ -566,65 +559,6 @@ def _find_blurb_dir(): return None -@subcommand -def release(version): - """ -Move all new blurbs to a single blurb file for the release. - -This is used by the release manager when cutting a new release. - """ - if version == ".": - # harvest version number from dirname of repo - # I remind you, we're in the Misc subdir right now - version = os.path.basename(root) - - existing_filenames = glob_blurbs(version) - if existing_filenames: - error("Sorry, can't handle appending 'next' files to an existing version (yet).") - - output = f"Misc/NEWS.d/{version}.rst" - filenames = glob_blurbs("next") - blurbs = Blurbs() - date = current_date() - - if not filenames: - print(f"No blurbs found. Setting {version} as having no changes.") - body = f"There were no new changes in version {version}.\n" - metadata = {"no changes": "True", "gh-issue": "0", "section": "Library", "date": date, "nonce": nonceify(body)} - blurbs.append((metadata, body)) - else: - count = len(filenames) - print(f'Merging {count} blurbs to "{output}".') - - for filename in filenames: - if not filename.endswith(".rst"): - continue - blurbs.load_next(filename) - - metadata = blurbs[0][0] - - metadata['release date'] = date - print("Saving.") - - blurbs.save(output) - git_add_files.append(output) - flush_git_add_files() - - how_many = len(filenames) - print(f"Removing {how_many} 'next' files from git.") - git_rm_files.extend(filenames) - flush_git_rm_files() - - # sanity check: ensuring that saving/reloading the merged blurb file works. - blurbs2 = Blurbs() - blurbs2.load(output) - assert blurbs2 == blurbs, f"Reloading {output} isn't reproducible?!" - - print() - print("Ready for commit.") - - - @subcommand def merge(output=None, *, forced=False): """ diff --git a/tests/test_blurb.py b/tests/test_blurb.py index 2339366..2ade934 100644 --- a/tests/test_blurb.py +++ b/tests/test_blurb.py @@ -88,11 +88,6 @@ def test_textwrap_body(body, subsequent_indent, expected): assert blurb.textwrap_body(body, subsequent_indent=subsequent_indent) == expected -@time_machine.travel("2025-01-07") -def test_current_date(): - assert blurb.current_date() == "2025-01-07" - - @time_machine.travel("2025-01-07 16:28:41") def test_sortable_datetime(): assert blurb.sortable_datetime() == "2025-01-07-16-28-41" diff --git a/tests/test_release.py b/tests/test_release.py new file mode 100644 index 0000000..3b4d25b --- /dev/null +++ b/tests/test_release.py @@ -0,0 +1,8 @@ +import time_machine + +from blurb._release import current_date + + +@time_machine.travel("2025-01-07") +def test_current_date(): + assert current_date() == "2025-01-07" From c92e5e1cb05d3fc9060cbcbac8638f16a7867d92 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:10:58 +0100 Subject: [PATCH 2/3] fixup! Move 'blurb release' to ``blurb._release`` --- src/blurb/_cli.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/blurb/_cli.py b/src/blurb/_cli.py index ca58214..123da51 100644 --- a/src/blurb/_cli.py +++ b/src/blurb/_cli.py @@ -5,8 +5,6 @@ import re import sys -import blurb.blurb - TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Callable @@ -298,5 +296,6 @@ def test_first_line(filename, test): break + import blurb.blurb blurb.blurb.root = path return path From a05a5ac8d0c3c071d7d269f0c06284c632b0560c Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Wed, 13 Aug 2025 01:11:59 +0100 Subject: [PATCH 3/3] fixup! Move 'blurb release' to ``blurb._release`` --- src/blurb/_cli.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/blurb/_cli.py b/src/blurb/_cli.py index 123da51..7e214a1 100644 --- a/src/blurb/_cli.py +++ b/src/blurb/_cli.py @@ -5,6 +5,8 @@ import re import sys +import blurb + TYPE_CHECKING = False if TYPE_CHECKING: from collections.abc import Callable