Skip to content

Commit c56c5c5

Browse files
Meta: Allow adding date to Resolution header (#4061)
Fixes #4054 Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 6fd5759 commit c56c5c5

File tree

8 files changed

+60
-10
lines changed

8 files changed

+60
-10
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ repos:
211211
files: '^peps/pep-\d+\.rst$'
212212

213213
- id: validate-resolution
214-
name: "'Resolution' must be a direct thread/message URL"
214+
name: "'Resolution' must be a direct thread/message URL or '`DD-mmm-YYYY <URL>`__'"
215215
language: pygrep
216-
entry: '(?<!\n\n)(?<=\n)Resolution: (?:(?!https://((discuss\.python\.org/t/([\w\-]+/)?\d+(/\d+)?/?)|(mail\.python\.org/pipermail/[\w\-]+/\d{4}-[A-Za-z]+/[A-Za-z0-9]+\.html)|(mail\.python\.org/archives/list/[\w\-]+@python\.org/(message|thread)/[A-Za-z0-9]+/?(#[A-Za-z0-9]+)?))\n))'
216+
entry: '(?<!\n\n)(?<=\n)Resolution: (?:(?!https://((discuss\.python\.org/t/([\w\-]+/)?\d+(/\d+)?/?)|(mail\.python\.org/pipermail/[\w\-]+/\d{4}-[A-Za-z]+/[A-Za-z0-9]+\.html)|(mail\.python\.org/archives/list/[\w\-]+@python\.org/(message|thread)/[A-Za-z0-9]+/?(#[A-Za-z0-9]+)?)))|`([0-2][0-9]|(3[01]))-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(199[0-9]|20[0-9][0-9]) <(?:(?!https://((discuss\.python\.org/t/([\w\-]+/)?\d+(/\d+)?/?)|(mail\.python\.org/pipermail/[\w\-]+/\d{4}-[A-Za-z]+/[A-Za-z0-9]+\.html)|(mail\.python\.org/archives/list/[\w\-]+@python\.org/(message|thread)/[A-Za-z0-9]+/?(#[A-Za-z0-9]+)?)))>`__))\n'
217217
args: ['--multiline']
218218
files: '^peps/pep-\d+\.rst$'
219219

check-peps.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ def _validate_python_version(line_num: int, line: str) -> MessageIterator:
407407

408408

409409
def _validate_post_history(line_num: int, body: str) -> MessageIterator:
410-
"""'Post-History' must be '`DD-mmm-YYYY <Thread URL>`__, …'"""
410+
"""'Post-History' must be '`DD-mmm-YYYY <Thread URL>`__, …' or `DD-mmm-YYYY`"""
411411

412412
if body == "":
413413
return
@@ -422,19 +422,28 @@ def _validate_post_history(line_num: int, body: str) -> MessageIterator:
422422
yield from _date(offset, post_date, "Post-History")
423423
yield from _thread(offset, post_url, "Post-History")
424424
else:
425-
yield offset, f"post line must be a date or both start with “`” and end with “>`__”"
425+
yield offset, "post line must be a date or both start with “`” and end with “>`__”"
426426

427427

428428
def _validate_resolution(line_num: int, line: str) -> MessageIterator:
429-
"""'Resolution' must be a direct thread/message URL"""
430-
431-
yield from _thread(line_num, line, "Resolution", allow_message=True)
429+
"""'Resolution' must be a direct thread/message URL or a link with a date."""
430+
431+
prefix, postfix = (line.startswith("`"), line.endswith(">`__"))
432+
if not prefix and not postfix:
433+
yield from _thread(line_num, line, "Resolution", allow_message=True)
434+
elif prefix and postfix:
435+
post_date, post_url = line[1:-4].split(" <")
436+
yield from _date(line_num, post_date, "Resolution")
437+
yield from _thread(line_num, post_url, "Resolution", allow_message=True)
438+
else:
439+
yield line_num, "Resolution line must be a link or both start with “`” and end with “>`__”"
432440

433441

434442
########################
435443
# Validation Helpers #
436444
########################
437445

446+
438447
def _pep_num(line_num: int, pep_number: str, prefix: str) -> MessageIterator:
439448
if pep_number == "":
440449
yield line_num, f"{prefix} must not be blank: {pep_number!r}"

pep_sphinx_extensions/pep_processor/transforms/pep_headers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ def apply(self) -> None:
119119
if (not isinstance(node, nodes.reference)
120120
or not node["refuri"]):
121121
continue
122+
# If the Resolution header is already a link, don't prettify it
123+
if name == "resolution" and node["refuri"] != node[0]:
124+
continue
122125
# Have known mailto links link to their main list pages
123126
if node["refuri"].lower().startswith("mailto:"):
124127
node["refuri"] = _generate_list_url(node["refuri"])

pep_sphinx_extensions/tests/pep_lint/test_pep_lint.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import check_peps # NoQA: inserted into sys.modules in conftest.py
44

5+
from ..conftest import PEP_ROOT
6+
57
PEP_9002 = Path(__file__).parent.parent / "peps" / "pep-9002.rst"
68

79

@@ -46,3 +48,10 @@ def test_with_fake_pep():
4648
(20, "Resolution must be a valid thread URL"),
4749
(23, "Use the :pep:`NNN` role to refer to PEPs"),
4850
]
51+
52+
53+
def test_skip_direct_pep_link_check():
54+
filename = PEP_ROOT / "pep-0009.rst" # in SKIP_DIRECT_PEP_LINK_CHECK
55+
content = filename.read_text(encoding="utf-8").splitlines()
56+
warnings = list(check_peps.check_peps(filename, content))
57+
assert warnings == []

pep_sphinx_extensions/tests/pep_lint/test_post_url.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ def test_validate_post_history_valid(body: str):
7979
assert warnings == [], warnings
8080

8181

82+
@pytest.mark.parametrize(
83+
"body",
84+
[
85+
"31-Jul-2015 <https://discuss.python.org/t/123456>`__,",
86+
"`31-Jul-2015 <https://discuss.python.org/t/123456>",
87+
],
88+
)
89+
def test_validate_post_history_unbalanced_link(body: str):
90+
warnings = [warning for (_, warning) in check_peps._validate_post_history(1, body)]
91+
assert warnings == [
92+
"post line must be a date or both start with “`” and end with “>`__”"
93+
], warnings
94+
95+
8296
@pytest.mark.parametrize(
8397
"line",
8498
[
@@ -90,6 +104,7 @@ def test_validate_post_history_valid(body: str):
90104
"https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/#Anchor",
91105
"https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123#Anchor123",
92106
"https://mail.python.org/archives/list/list-name@python.org/message/abcXYZ123/#Anchor123",
107+
"`16-Oct-2024 <https://mail.python.org/archives/list/list-name@python.org/thread/abcXYZ123>`__",
93108
],
94109
)
95110
def test_validate_resolution_valid(line: str):
@@ -117,6 +132,20 @@ def test_validate_resolution_invalid(line: str):
117132
assert warnings == ["Resolution must be a valid thread URL"], warnings
118133

119134

135+
@pytest.mark.parametrize(
136+
"line",
137+
[
138+
"01-Jan-2000 <https://mail.python.org/pipermail/list-name/0000-Month/0123456.html>`__",
139+
"`01-Jan-2000 <https://mail.python.org/pipermail/list-name/0000-Month/0123456.html>",
140+
],
141+
)
142+
def test_validate_resolution_unbalanced_link(line: str):
143+
warnings = [warning for (_, warning) in check_peps._validate_resolution(1, line)]
144+
assert warnings == [
145+
"Resolution line must be a link or both start with “`” and end with “>`__”"
146+
], warnings
147+
148+
120149
@pytest.mark.parametrize(
121150
"thread_url",
122151
[

peps/pep-0001.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ optional and are described below. All other headers are required.
621621
inline-linked to PEP discussion threads>
622622
* Replaces: <pep number>
623623
* Superseded-By: <pep number>
624-
* Resolution: <url>
624+
* Resolution: <date in dd-mmm-yyyy format, linked to the acceptance/rejection post>
625625
626626
The Author header lists the names, and optionally the email addresses
627627
of all the authors/owners of the PEP. The format of the Author header

peps/pep-0702.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Created: 30-Dec-2022
99
Python-Version: 3.13
1010
Post-History: `01-Jan-2023 <https://mail.python.org/archives/list/typing-sig@python.org/thread/AKTFUYW3WDT7R7PGRIJQZMYHMDJNE4QH/>`__,
1111
`22-Jan-2023 <https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036>`__
12-
Resolution: https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036/61
12+
Resolution: `07-Nov-2023 <https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036/61>`__
1313

1414
.. canonical-typing-spec:: :ref:`typing:deprecated` and
1515
:external+py3.13:func:`@warnings.deprecated<warnings.deprecated>`

peps/pep-0735.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Type: Standards Track
99
Topic: Packaging
1010
Created: 20-Nov-2023
1111
Post-History: `14-Nov-2023 <https://discuss.python.org/t/29684>`__, `20-Nov-2023 <https://discuss.python.org/t/39233>`__
12-
Resolution: https://discuss.python.org/t/39233/312
12+
Resolution: `10-Oct-2024 <https://discuss.python.org/t/39233/312>`__
1313

1414

1515
Abstract

0 commit comments

Comments
 (0)