Skip to content

Commit fa99c26

Browse files
authored
Move 'blurb release' to blurb._release (#53)
1 parent de10fe8 commit fa99c26

File tree

5 files changed

+81
-73
lines changed

5 files changed

+81
-73
lines changed

src/blurb/_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,6 @@ def test_first_line(filename, test):
298298

299299
break
300300

301-
blurb.root = path
301+
import blurb.blurb
302+
blurb.blurb.root = path
302303
return path

src/blurb/_release.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import time
5+
6+
import blurb.blurb
7+
from blurb._cli import error, subcommand
8+
from blurb.blurb import (Blurbs, flush_git_add_files, flush_git_rm_files,
9+
git_rm_files, git_add_files, glob_blurbs, nonceify)
10+
11+
12+
@subcommand
13+
def release(version: str) -> None:
14+
"""Move all new blurbs to a single blurb file for the release.
15+
16+
This is used by the release manager when cutting a new release.
17+
"""
18+
if version == '.':
19+
# harvest version number from dirname of repo
20+
# I remind you, we're in the Misc subdir right now
21+
version = os.path.basename(blurb.blurb.root)
22+
23+
existing_filenames = glob_blurbs(version)
24+
if existing_filenames:
25+
error("Sorry, can't handle appending 'next' files to an existing version (yet).")
26+
27+
output = f'Misc/NEWS.d/{version}.rst'
28+
filenames = glob_blurbs('next')
29+
blurbs = Blurbs()
30+
date = current_date()
31+
32+
if not filenames:
33+
print(f'No blurbs found. Setting {version} as having no changes.')
34+
body = f'There were no new changes in version {version}.\n'
35+
metadata = {'no changes': 'True', 'gh-issue': '0', 'section': 'Library', 'date': date, 'nonce': nonceify(body)}
36+
blurbs.append((metadata, body))
37+
else:
38+
count = len(filenames)
39+
print(f'Merging {count} blurbs to "{output}".')
40+
41+
for filename in filenames:
42+
if not filename.endswith('.rst'):
43+
continue
44+
blurbs.load_next(filename)
45+
46+
metadata = blurbs[0][0]
47+
48+
metadata['release date'] = date
49+
print('Saving.')
50+
51+
blurbs.save(output)
52+
git_add_files.append(output)
53+
flush_git_add_files()
54+
55+
how_many = len(filenames)
56+
print(f"Removing {how_many} 'next' files from git.")
57+
git_rm_files.extend(filenames)
58+
flush_git_rm_files()
59+
60+
# sanity check: ensuring that saving/reloading the merged blurb file works.
61+
blurbs2 = Blurbs()
62+
blurbs2.load(output)
63+
assert blurbs2 == blurbs, f"Reloading {output} isn't reproducible?!"
64+
65+
print()
66+
print('Ready for commit.')
67+
68+
69+
def current_date() -> str:
70+
return time.strftime('%Y-%m-%d', time.localtime())

src/blurb/blurb.py

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#
4040
# automatic git adds and removes
4141

42-
import atexit
4342
import base64
4443
import builtins
4544
import glob
@@ -49,18 +48,16 @@
4948
import os
5049
from pathlib import Path
5150
import re
52-
import shlex
5351
import shutil
5452
import subprocess
5553
import sys
56-
import tempfile
5754
import textwrap
5855
import time
5956

6057
from blurb._cli import main, subcommand
6158
from blurb._template import (
6259
next_filename_unsanitize_sections, sanitize_section,
63-
sanitize_section_legacy, sections, template, unsanitize_section,
60+
sanitize_section_legacy, sections, unsanitize_section,
6461
)
6562

6663
root = None # Set by chdir_to_repo_root()
@@ -156,10 +153,6 @@ def textwrap_body(body, *, subsequent_indent=''):
156153
text += "\n"
157154
return text
158155

159-
160-
def current_date():
161-
return time.strftime("%Y-%m-%d", time.localtime())
162-
163156
def sortable_datetime():
164157
return time.strftime("%Y-%m-%d-%H-%M-%S", time.localtime())
165158

@@ -566,65 +559,6 @@ def _find_blurb_dir():
566559
return None
567560

568561

569-
@subcommand
570-
def release(version):
571-
"""
572-
Move all new blurbs to a single blurb file for the release.
573-
574-
This is used by the release manager when cutting a new release.
575-
"""
576-
if version == ".":
577-
# harvest version number from dirname of repo
578-
# I remind you, we're in the Misc subdir right now
579-
version = os.path.basename(root)
580-
581-
existing_filenames = glob_blurbs(version)
582-
if existing_filenames:
583-
error("Sorry, can't handle appending 'next' files to an existing version (yet).")
584-
585-
output = f"Misc/NEWS.d/{version}.rst"
586-
filenames = glob_blurbs("next")
587-
blurbs = Blurbs()
588-
date = current_date()
589-
590-
if not filenames:
591-
print(f"No blurbs found. Setting {version} as having no changes.")
592-
body = f"There were no new changes in version {version}.\n"
593-
metadata = {"no changes": "True", "gh-issue": "0", "section": "Library", "date": date, "nonce": nonceify(body)}
594-
blurbs.append((metadata, body))
595-
else:
596-
count = len(filenames)
597-
print(f'Merging {count} blurbs to "{output}".')
598-
599-
for filename in filenames:
600-
if not filename.endswith(".rst"):
601-
continue
602-
blurbs.load_next(filename)
603-
604-
metadata = blurbs[0][0]
605-
606-
metadata['release date'] = date
607-
print("Saving.")
608-
609-
blurbs.save(output)
610-
git_add_files.append(output)
611-
flush_git_add_files()
612-
613-
how_many = len(filenames)
614-
print(f"Removing {how_many} 'next' files from git.")
615-
git_rm_files.extend(filenames)
616-
flush_git_rm_files()
617-
618-
# sanity check: ensuring that saving/reloading the merged blurb file works.
619-
blurbs2 = Blurbs()
620-
blurbs2.load(output)
621-
assert blurbs2 == blurbs, f"Reloading {output} isn't reproducible?!"
622-
623-
print()
624-
print("Ready for commit.")
625-
626-
627-
628562
@subcommand
629563
def merge(output=None, *, forced=False):
630564
"""

tests/test_blurb.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ def test_textwrap_body(body, subsequent_indent, expected):
8888
assert blurb.textwrap_body(body, subsequent_indent=subsequent_indent) == expected
8989

9090

91-
@time_machine.travel("2025-01-07")
92-
def test_current_date():
93-
assert blurb.current_date() == "2025-01-07"
94-
95-
9691
@time_machine.travel("2025-01-07 16:28:41")
9792
def test_sortable_datetime():
9893
assert blurb.sortable_datetime() == "2025-01-07-16-28-41"

tests/test_release.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import time_machine
2+
3+
from blurb._release import current_date
4+
5+
6+
@time_machine.travel("2025-01-07")
7+
def test_current_date():
8+
assert current_date() == "2025-01-07"

0 commit comments

Comments
 (0)