Skip to content
Open
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
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ repos:
- id: ruff-check
args: [--exit-non-zero-on-fix]
- id: ruff-format
args: [--check]

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.33.2
Expand Down
1 change: 1 addition & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target-version = "py310"
fix = true

[format]
preview = true
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.2.0

* Keep sections in importance order by @hugovk in https://github.com/python/blurb/pull/75

## 2.1.0

- Add the `-i` / `--issue` option to the 'blurb add' command.
Expand Down
33 changes: 22 additions & 11 deletions src/blurb/_utils/globs.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@
def glob_blurbs(version: str) -> list[str]:
filenames = []
base = os.path.join('Misc', 'NEWS.d', version)

if version != 'next':
wildcard = f'{base}.rst'
filenames.extend(glob.glob(wildcard))
else:
sanitized_sections = set(map(sanitize_section, sections))
sanitized_sections |= set(map(sanitize_section_legacy, sections))
for section in sanitized_sections:
wildcard = os.path.join(base, section, '*.rst')
entries = glob.glob(wildcard)
deletables = [x for x in entries if x.endswith('/README.rst')]
for filename in deletables:
entries.remove(filename)
filenames.extend(entries)
filenames.sort(reverse=True, key=next_filename_unsanitize_sections)
return filenames

for section in sections:
entries = []
seen_dirs = set()
for dir_name in (
sanitize_section(section),
sanitize_section_legacy(section),
):
if dir_name in seen_dirs:
continue

seen_dirs.add(dir_name)
wildcard = os.path.join(base, dir_name, '*.rst')
for entry in glob.glob(wildcard):
if not entry.endswith('/README.rst'):
entries.append(entry)

entries.sort(reverse=True, key=next_filename_unsanitize_sections)
filenames.extend(entries)

return filenames
30 changes: 30 additions & 0 deletions tests/test_utils_globs.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,33 @@ def test_glob_blurbs_sort_order(fs) -> None:

# Assert
assert filenames == expected


def test_glob_blurbs_section_ordering(fs) -> None:
"""Sections must appear in importance order, not alphabetical order.
The canonical order is: Security, Core and Builtins, Library,
Documentation, Tests, Build, Windows, macOS, IDLE, Tools/Demos, C API.
"""
# Arrange: one entry per section
fake_news_entries = [
'Misc/NEWS.d/next/Security/2024-01-01-00-00-00.gh-issue-00000.aAAAAA.rst',
'Misc/NEWS.d/next/Core_and_Builtins/2024-01-01-00-00-00.gh-issue-00001.bBBBBB.rst',
'Misc/NEWS.d/next/Library/2024-01-01-00-00-00.gh-issue-00002.cCCCCC.rst',
'Misc/NEWS.d/next/Documentation/2024-01-01-00-00-00.gh-issue-00003.dDDDDD.rst',
'Misc/NEWS.d/next/Tests/2024-01-01-00-00-00.gh-issue-00004.eEEEEE.rst',
'Misc/NEWS.d/next/Build/2024-01-01-00-00-00.gh-issue-00005.fFFFFF.rst',
'Misc/NEWS.d/next/Windows/2024-01-01-00-00-00.gh-issue-00006.gGGGGG.rst',
'Misc/NEWS.d/next/macOS/2024-01-01-00-00-00.gh-issue-00007.hHHHHH.rst',
'Misc/NEWS.d/next/IDLE/2024-01-01-00-00-00.gh-issue-00008.iIIIII.rst',
'Misc/NEWS.d/next/Tools-Demos/2024-01-01-00-00-00.gh-issue-00009.jJJJJJ.rst',
'Misc/NEWS.d/next/C_API/2024-01-01-00-00-00.gh-issue-00010.kKKKKK.rst',
]
for path in fake_news_entries:
fs.create_file(path)

# Act
filenames = glob_blurbs('next')

# Assert: must be in importance order, not alphabetical
assert filenames == fake_news_entries
Loading