Skip to content

Commit a1b2a4f

Browse files
committed
Update PEP number in README.rst
1 parent 11982d8 commit a1b2a4f

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

release.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import datetime
1212
import glob
1313
import hashlib
14+
import json
1415
import optparse
1516
import os
1617
import re
@@ -19,9 +20,11 @@
1920
import subprocess
2021
import sys
2122
import tempfile
23+
import urllib.request
2224
from collections.abc import Generator, Sequence
2325
from contextlib import contextmanager
2426
from dataclasses import dataclass
27+
from functools import cache
2528
from pathlib import Path
2629
from typing import (
2730
Any,
@@ -442,6 +445,22 @@ def tweak_patchlevel(
442445
print("done")
443446

444447

448+
@cache
449+
def get_pep_number(version: str) -> str:
450+
"""Fetch PEP number for a Python version from the devguide.
451+
452+
Returns the PEP number as a string, or "TODO" if not found.
453+
"""
454+
url = "https://raw.githubusercontent.com/python/devguide/main/include/release-cycle.json"
455+
with urllib.request.urlopen(url, timeout=10) as response:
456+
data = json.loads(response.read().decode())
457+
if version in data:
458+
pep = data[version].get("pep")
459+
if pep:
460+
return str(pep)
461+
return "TODO"
462+
463+
445464
def tweak_readme(tag: Tag, filename: str = "README.rst") -> None:
446465
print(f"Updating {filename}...", end=" ")
447466
readme = Path(filename)
@@ -473,10 +492,14 @@ def tweak_readme(tag: Tag, filename: str = "README.rst") -> None:
473492
content,
474493
)
475494

476-
# Replace in "for Python 3.14 release details"
495+
# Get PEP number for this version
496+
pep_number = get_pep_number(tag.basic_version)
497+
pep_padded = pep_number.zfill(4) if pep_number != "TODO" else "TODO"
498+
499+
# Replace in: `PEP 745 <https://peps.python.org/pep-0745/>`__ for Python 3.14
477500
content = re.sub(
478-
rf"(for Python ){X_Y}( release details)",
479-
rf"\g<1>{tag.basic_version}\g<2>",
501+
rf"(`PEP )\d+( <https://peps\.python\.org/pep-)\d+(/>`__ for Python ){X_Y}",
502+
rf"\g<1>{pep_number}\g<2>{pep_padded}\g<3>{tag.basic_version}",
480503
content,
481504
)
482505

tests/test_release.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_tweak_patchlevel(tmp_path: Path) -> None:
7777
"expected_underline",
7878
"expected_whatsnew",
7979
"expected_docs",
80-
"expected_release_details_text",
80+
"expected_pep_line",
8181
],
8282
[
8383
(
@@ -86,31 +86,31 @@ def test_tweak_patchlevel(tmp_path: Path) -> None:
8686
"=====================================",
8787
"3.14 <https://docs.python.org/3.14/whatsnew/3.14.html>`_",
8888
"`Documentation for Python 3.14 <https://docs.python.org/3.14/>`_",
89-
"for Python 3.14 release details",
89+
"`PEP 745 <https://peps.python.org/pep-0745/>`__ for Python 3.14",
9090
),
9191
(
9292
"3.14.0b2",
9393
"This is Python version 3.14.0 beta 2",
9494
"====================================",
9595
"3.14 <https://docs.python.org/3.14/whatsnew/3.14.html>`_",
9696
"`Documentation for Python 3.14 <https://docs.python.org/3.14/>`_",
97-
"for Python 3.14 release details",
97+
"`PEP 745 <https://peps.python.org/pep-0745/>`__ for Python 3.14",
9898
),
9999
(
100100
"3.14.0rc2",
101101
"This is Python version 3.14.0 release candidate 2",
102102
"=================================================",
103103
"3.14 <https://docs.python.org/3.14/whatsnew/3.14.html>`_",
104104
"`Documentation for Python 3.14 <https://docs.python.org/3.14/>`_",
105-
"for Python 3.14 release details",
105+
"`PEP 745 <https://peps.python.org/pep-0745/>`__ for Python 3.14",
106106
),
107107
(
108108
"3.15.1",
109109
"This is Python version 3.15.1",
110110
"=============================",
111111
"3.15 <https://docs.python.org/3.15/whatsnew/3.15.html>`_",
112112
"`Documentation for Python 3.15 <https://docs.python.org/3.15/>`_",
113-
"for Python 3.15 release details",
113+
"`PEP 790 <https://peps.python.org/pep-0790/>`__ for Python 3.15",
114114
),
115115
],
116116
)
@@ -121,7 +121,7 @@ def test_tweak_readme(
121121
expected_underline: str,
122122
expected_whatsnew: str,
123123
expected_docs: str,
124-
expected_release_details_text: str,
124+
expected_pep_line: str,
125125
) -> None:
126126
# Arrange
127127
tag = release.Tag(test_tag)
@@ -141,4 +141,4 @@ def test_tweak_readme(
141141
assert new_lines[1] == expected_underline
142142
assert expected_whatsnew in new_contents
143143
assert expected_docs in new_contents
144-
assert expected_release_details_text in new_contents
144+
assert expected_pep_line in new_contents

0 commit comments

Comments
 (0)