Skip to content

Move 'blurb release' to blurb._release #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 13, 2025
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
3 changes: 2 additions & 1 deletion src/blurb/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,5 +298,6 @@ def test_first_line(filename, test):

break

blurb.root = path
import blurb.blurb
blurb.blurb.root = path
return path
70 changes: 70 additions & 0 deletions src/blurb/_release.py
Original file line number Diff line number Diff line change
@@ -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())
68 changes: 1 addition & 67 deletions src/blurb/blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#
# automatic git adds and removes

import atexit
import base64
import builtins
import glob
Expand All @@ -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()
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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):
"""
Expand Down
5 changes: 0 additions & 5 deletions tests/test_blurb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions tests/test_release.py
Original file line number Diff line number Diff line change
@@ -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"