Skip to content

Commit f8fc381

Browse files
authored
Keep sections in importance order (#75)
2 parents c8893e0 + 2ca8009 commit f8fc381

File tree

5 files changed

+57
-12
lines changed

5 files changed

+57
-12
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ repos:
1818
- id: ruff-check
1919
args: [--exit-non-zero-on-fix]
2020
- id: ruff-format
21-
args: [--check]
2221

2322
- repo: https://github.com/python-jsonschema/check-jsonschema
2423
rev: 0.33.2

.ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target-version = "py310"
2+
fix = true
23

34
[format]
45
preview = true

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 2.2.0
4+
5+
* Keep sections in importance order by @hugovk in https://github.com/python/blurb/pull/75
6+
37
## 2.1.0
48

59
- Add the `-i` / `--issue` option to the 'blurb add' command.

src/blurb/_utils/globs.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,29 @@
1414
def glob_blurbs(version: str) -> list[str]:
1515
filenames = []
1616
base = os.path.join('Misc', 'NEWS.d', version)
17+
1718
if version != 'next':
1819
wildcard = f'{base}.rst'
1920
filenames.extend(glob.glob(wildcard))
20-
else:
21-
sanitized_sections = set(map(sanitize_section, sections))
22-
sanitized_sections |= set(map(sanitize_section_legacy, sections))
23-
for section in sanitized_sections:
24-
wildcard = os.path.join(base, section, '*.rst')
25-
entries = glob.glob(wildcard)
26-
deletables = [x for x in entries if x.endswith('/README.rst')]
27-
for filename in deletables:
28-
entries.remove(filename)
29-
filenames.extend(entries)
30-
filenames.sort(reverse=True, key=next_filename_unsanitize_sections)
21+
return filenames
22+
23+
for section in sections:
24+
entries = []
25+
seen_dirs = set()
26+
for dir_name in (
27+
sanitize_section(section),
28+
sanitize_section_legacy(section),
29+
):
30+
if dir_name in seen_dirs:
31+
continue
32+
33+
seen_dirs.add(dir_name)
34+
wildcard = os.path.join(base, dir_name, '*.rst')
35+
for entry in glob.glob(wildcard):
36+
if not entry.endswith('/README.rst'):
37+
entries.append(entry)
38+
39+
entries.sort(reverse=True, key=next_filename_unsanitize_sections)
40+
filenames.extend(entries)
41+
3142
return filenames

tests/test_utils_globs.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,33 @@ def test_glob_blurbs_sort_order(fs) -> None:
5858

5959
# Assert
6060
assert filenames == expected
61+
62+
63+
def test_glob_blurbs_section_ordering(fs) -> None:
64+
"""Sections must appear in importance order, not alphabetical order.
65+
66+
The canonical order is: Security, Core and Builtins, Library,
67+
Documentation, Tests, Build, Windows, macOS, IDLE, Tools/Demos, C API.
68+
"""
69+
# Arrange: one entry per section
70+
fake_news_entries = [
71+
'Misc/NEWS.d/next/Security/2024-01-01-00-00-00.gh-issue-00000.aAAAAA.rst',
72+
'Misc/NEWS.d/next/Core_and_Builtins/2024-01-01-00-00-00.gh-issue-00001.bBBBBB.rst',
73+
'Misc/NEWS.d/next/Library/2024-01-01-00-00-00.gh-issue-00002.cCCCCC.rst',
74+
'Misc/NEWS.d/next/Documentation/2024-01-01-00-00-00.gh-issue-00003.dDDDDD.rst',
75+
'Misc/NEWS.d/next/Tests/2024-01-01-00-00-00.gh-issue-00004.eEEEEE.rst',
76+
'Misc/NEWS.d/next/Build/2024-01-01-00-00-00.gh-issue-00005.fFFFFF.rst',
77+
'Misc/NEWS.d/next/Windows/2024-01-01-00-00-00.gh-issue-00006.gGGGGG.rst',
78+
'Misc/NEWS.d/next/macOS/2024-01-01-00-00-00.gh-issue-00007.hHHHHH.rst',
79+
'Misc/NEWS.d/next/IDLE/2024-01-01-00-00-00.gh-issue-00008.iIIIII.rst',
80+
'Misc/NEWS.d/next/Tools-Demos/2024-01-01-00-00-00.gh-issue-00009.jJJJJJ.rst',
81+
'Misc/NEWS.d/next/C_API/2024-01-01-00-00-00.gh-issue-00010.kKKKKK.rst',
82+
]
83+
for path in fake_news_entries:
84+
fs.create_file(path)
85+
86+
# Act
87+
filenames = glob_blurbs('next')
88+
89+
# Assert: must be in importance order, not alphabetical
90+
assert filenames == fake_news_entries

0 commit comments

Comments
 (0)