Skip to content

Commit 2bc3234

Browse files
committed
Undo moving glob_blurbs
1 parent aa3bf05 commit 2bc3234

File tree

4 files changed

+86
-89
lines changed

4 files changed

+86
-89
lines changed

src/blurb/_merge.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
import glob
21
import os
32
import sys
43
from pathlib import Path
54

65
from blurb._cli import require_ok, subcommand
7-
from blurb._template import (
8-
next_filename_unsanitize_sections, sanitize_section,
9-
sanitize_section_legacy, sections,
10-
)
116
from blurb._versions import glob_versions, printable_version
12-
from blurb.blurb import Blurbs, textwrap_body
7+
from blurb.blurb import Blurbs, glob_blurbs, textwrap_body
138

149
original_dir: str = os.getcwd()
1510

@@ -122,25 +117,3 @@ def prnt(msg: str = '', /):
122117
Path(output).write_text(new_contents, encoding='utf-8')
123118
else:
124119
print(output, 'is already up to date')
125-
126-
127-
def glob_blurbs(version: str) -> list[str]:
128-
filenames = []
129-
base = os.path.join('Misc', 'NEWS.d', version)
130-
if version != 'next':
131-
wildcard = f'{base}.rst'
132-
filenames.extend(glob.glob(wildcard))
133-
else:
134-
sanitized_sections = (
135-
{sanitize_section(section) for section in sections} |
136-
{sanitize_section_legacy(section) for section in sections}
137-
)
138-
for section in sanitized_sections:
139-
wildcard = os.path.join(base, section, '*.rst')
140-
entries = glob.glob(wildcard)
141-
deletables = [x for x in entries if x.endswith('/README.rst')]
142-
for filename in deletables:
143-
entries.remove(filename)
144-
filenames.extend(entries)
145-
filenames.sort(reverse=True, key=next_filename_unsanitize_sections)
146-
return filenames

src/blurb/blurb.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@
5252

5353
from blurb._cli import main, subcommand
5454
from blurb._git import git_add_files, flush_git_add_files
55-
from blurb._template import sanitize_section, sections, unsanitize_section
55+
from blurb._template import (
56+
next_filename_unsanitize_sections, sanitize_section,
57+
sanitize_section_legacy, sections, unsanitize_section,
58+
)
5659

5760
root = None # Set by chdir_to_repo_root()
5861

@@ -155,6 +158,28 @@ def nonceify(body):
155158
return base64.urlsafe_b64encode(digest)[0:6].decode('ascii')
156159

157160

161+
def glob_blurbs(version):
162+
filenames = []
163+
base = os.path.join("Misc", "NEWS.d", version)
164+
if version != "next":
165+
wildcard = base + ".rst"
166+
filenames.extend(glob.glob(wildcard))
167+
else:
168+
sanitized_sections = (
169+
{sanitize_section(section) for section in sections} |
170+
{sanitize_section_legacy(section) for section in sections}
171+
)
172+
for section in sanitized_sections:
173+
wildcard = os.path.join(base, section, "*.rst")
174+
entries = glob.glob(wildcard)
175+
deletables = [x for x in entries if x.endswith("/README.rst")]
176+
for filename in deletables:
177+
entries.remove(filename)
178+
filenames.extend(entries)
179+
filenames.sort(reverse=True, key=next_filename_unsanitize_sections)
180+
return filenames
181+
182+
158183
class BlurbError(RuntimeError):
159184
pass
160185

tests/test_blurb.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,65 @@ def test_sortable_datetime():
9393
assert blurb.sortable_datetime() == "2025-01-07-16-28-41"
9494

9595

96+
def test_glob_blurbs_next(fs):
97+
# Arrange
98+
fake_news_entries = (
99+
"Misc/NEWS.d/next/Library/2022-04-11-18-34-33.gh-issue-11111.pC7gnM.rst",
100+
"Misc/NEWS.d/next/Core and Builtins/2023-03-17-12-09-45.gh-issue-33333.Pf_BI7.rst",
101+
"Misc/NEWS.d/next/Tools-Demos/2023-03-21-01-27-07.gh-issue-44444.2F1Byz.rst",
102+
"Misc/NEWS.d/next/C API/2023-03-27-22-09-07.gh-issue-66666.3SN8Bs.rst",
103+
)
104+
fake_readmes = (
105+
"Misc/NEWS.d/next/Library/README.rst",
106+
"Misc/NEWS.d/next/Core and Builtins/README.rst",
107+
"Misc/NEWS.d/next/Tools-Demos/README.rst",
108+
"Misc/NEWS.d/next/C API/README.rst",
109+
)
110+
for fn in fake_news_entries + fake_readmes:
111+
fs.create_file(fn)
112+
113+
# Act
114+
filenames = blurb.glob_blurbs("next")
115+
116+
# Assert
117+
assert set(filenames) == set(fake_news_entries)
118+
119+
120+
def test_glob_blurbs_sort_order(fs):
121+
"""
122+
It shouldn't make a difference to sorting whether
123+
section names have spaces or underscores.
124+
"""
125+
# Arrange
126+
fake_news_entries = (
127+
"Misc/NEWS.d/next/Core and Builtins/2023-07-23-12-01-00.gh-issue-33331.Pf_BI1.rst",
128+
"Misc/NEWS.d/next/Core_and_Builtins/2023-07-23-12-02-00.gh-issue-33332.Pf_BI2.rst",
129+
"Misc/NEWS.d/next/Core and Builtins/2023-07-23-12-03-00.gh-issue-33333.Pf_BI3.rst",
130+
"Misc/NEWS.d/next/Core_and_Builtins/2023-07-23-12-04-00.gh-issue-33334.Pf_BI4.rst",
131+
)
132+
# As fake_news_entries, but reverse sorted by *filename* only
133+
expected = [
134+
"Misc/NEWS.d/next/Core_and_Builtins/2023-07-23-12-04-00.gh-issue-33334.Pf_BI4.rst",
135+
"Misc/NEWS.d/next/Core and Builtins/2023-07-23-12-03-00.gh-issue-33333.Pf_BI3.rst",
136+
"Misc/NEWS.d/next/Core_and_Builtins/2023-07-23-12-02-00.gh-issue-33332.Pf_BI2.rst",
137+
"Misc/NEWS.d/next/Core and Builtins/2023-07-23-12-01-00.gh-issue-33331.Pf_BI1.rst",
138+
]
139+
fake_readmes = (
140+
"Misc/NEWS.d/next/Library/README.rst",
141+
"Misc/NEWS.d/next/Core and Builtins/README.rst",
142+
"Misc/NEWS.d/next/Tools-Demos/README.rst",
143+
"Misc/NEWS.d/next/C API/README.rst",
144+
)
145+
for fn in fake_news_entries + fake_readmes:
146+
fs.create_file(fn)
147+
148+
# Act
149+
filenames = blurb.glob_blurbs("next")
150+
151+
# Assert
152+
assert filenames == expected
153+
154+
96155
@pytest.mark.parametrize(
97156
"news_entry, expected_section",
98157
(

tests/test_merge.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)