Skip to content

Commit

Permalink
Allow resolution date in Resolution header
Browse files Browse the repository at this point in the history
Fixes #4054
  • Loading branch information
JelleZijlstra committed Oct 16, 2024
1 parent a4feace commit d764a9d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ repos:
- id: validate-resolution
name: "'Resolution' must be a direct thread/message URL or '`DD-mmm-YYYY <URL>`__'"
language: pygrep
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))|`([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))>`__)'
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'
args: ['--multiline']
files: '^peps/pep-\d+\.rst$'

Expand Down
32 changes: 27 additions & 5 deletions check-peps.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ def _validate_python_version(line_num: int, line: str) -> MessageIterator:


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

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


def _validate_resolution(line_num: int, line: str) -> MessageIterator:
"""'Resolution' must be a direct thread/message URL"""

yield from _thread(line_num, line, "Resolution", allow_message=True)
"""'Resolution' must be a direct thread/message URL or a link with a date."""

prefix, postfix = (line.startswith("`"), line.endswith(">`__"))
if not prefix and not postfix:
yield from _thread(line_num, line, "Resolution", allow_message=True)
elif prefix and postfix:
post_date, post_url = line[1:-4].split(" <")
yield from _date(line_num, post_date, "Resolution")
yield from _thread(line_num, post_url, "Resolution")
else:
yield line_num, "Resolution line must be a link or both start with “`” and end with “>`__”"


########################
# Validation Helpers #
########################

def _validate_link_or_thread(text: str, header: str, offset: int, *, allow_message: bool = False) -> MessageIterator:
prefix, postfix = (text.startswith("`"), text.endswith(">`__"))
if not prefix and not postfix:
if header == "Resolution":
yield from _thread(line_num, line, "Resolution", allow_message=True)
yield from _date(offset, text, header)
elif prefix and postfix:
post_date, post_url = text[1:-4].split(" <")
yield from _date(offset, post_date, header)
yield from _thread(offset, post_url, header)
else:
yield offset, f"{header} line must be a date or both start with “`” and end with “>`__”"


def _pep_num(line_num: int, pep_number: str, prefix: str) -> MessageIterator:
if pep_number == "":
yield line_num, f"{prefix} must not be blank: {pep_number!r}"
Expand Down
4 changes: 4 additions & 0 deletions pep_sphinx_extensions/pep_processor/transforms/pep_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,13 @@ def apply(self) -> None:
elif name in {"discussions-to", "resolution", "post-history"}:
# Prettify mailing list and Discourse links
for node in para:
print(name, para, node)
if (not isinstance(node, nodes.reference)
or not node["refuri"]):
continue
# If the Resolution header is already a link, don't prettify it
if name == "resolution" and node["refuri"] != node[0]:
continue
# Have known mailto links link to their main list pages
if node["refuri"].lower().startswith("mailto:"):
node["refuri"] = _generate_list_url(node["refuri"])
Expand Down
1 change: 1 addition & 0 deletions pep_sphinx_extensions/tests/pep_lint/test_post_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def test_validate_post_history_valid(body: str):
"https://mail.python.org/archives/list/[email protected]/message/abcXYZ123/#Anchor",
"https://mail.python.org/archives/list/[email protected]/message/abcXYZ123#Anchor123",
"https://mail.python.org/archives/list/[email protected]/message/abcXYZ123/#Anchor123",
"`16-Oct-2024 <https://mail.python.org/archives/list/[email protected]/thread/abcXYZ123>`__",
],
)
def test_validate_resolution_valid(line: str):
Expand Down
2 changes: 1 addition & 1 deletion peps/pep-0001.rst
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ optional and are described below. All other headers are required.
inline-linked to PEP discussion threads>
* Replaces: <pep number>
* Superseded-By: <pep number>
* Resolution: <url>
* Resolution: <date in dd-mmm-yyyy format, linked to the acceptance/rejection post>
The Author header lists the names, and optionally the email addresses
of all the authors/owners of the PEP. The format of the Author header
Expand Down
2 changes: 1 addition & 1 deletion peps/pep-0702.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Created: 30-Dec-2022
Python-Version: 3.13
Post-History: `01-Jan-2023 <https://mail.python.org/archives/list/[email protected]/thread/AKTFUYW3WDT7R7PGRIJQZMYHMDJNE4QH/>`__,
`22-Jan-2023 <https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036>`__
Resolution: https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036/61
Resolution: `07-Nov-2023 <https://discuss.python.org/t/pep-702-marking-deprecations-using-the-type-system/23036/61>`__

.. canonical-typing-spec:: :ref:`typing:deprecated` and
:external+py3.13:func:`@warnings.deprecated<warnings.deprecated>`
Expand Down
2 changes: 1 addition & 1 deletion peps/pep-0735.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Type: Standards Track
Topic: Packaging
Created: 20-Nov-2023
Post-History: `14-Nov-2023 <https://discuss.python.org/t/29684>`__, `20-Nov-2023 <https://discuss.python.org/t/39233>`__
Resolution: https://discuss.python.org/t/39233/312
Resolution: `10-Oct-2024 <https://discuss.python.org/t/39233/312>`__


Abstract
Expand Down

0 comments on commit d764a9d

Please sign in to comment.