Skip to content

Commit 8d14d70

Browse files
committed
Meta: Add Sponsor to the PEP API
1 parent 0d2bacb commit 8d14d70

File tree

1 file changed

+42
-18
lines changed
  • pep_sphinx_extensions/pep_zero_generator

1 file changed

+42
-18
lines changed

pep_sphinx_extensions/pep_zero_generator/parser.py

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,24 @@
1818
from pep_sphinx_extensions.pep_zero_generator.errors import PEPError
1919

2020

21-
@dataclasses.dataclass(order=True, frozen=True)
22-
class _Author:
21+
_frozen_ordered = dataclasses.dataclass(order=True, frozen=True)
22+
23+
24+
@_frozen_ordered
25+
class _Participant:
26+
"""Represent PEP participant."""
27+
full_name: str # The participant's name.
28+
email: str # The participant's email address.
29+
30+
31+
@_frozen_ordered
32+
class _Author(_Participant):
2333
"""Represent PEP authors."""
24-
full_name: str # The author's name.
25-
email: str # The author's email address.
34+
35+
36+
@_frozen_ordered
37+
class _Sponsor(_Participant):
38+
"""Represent PEP sponsors."""
2639

2740

2841
class PEP:
@@ -95,6 +108,9 @@ def __init__(self, filename: Path):
95108
if not self.authors:
96109
raise _raise_pep_error(self, "no authors found", pep_num=True)
97110

111+
# Parse PEP sponsors
112+
self.sponsor: str | None = _parse_sponsor(metadata["Sponsor"]).full_name if metadata["Sponsor"] else None
113+
98114
# Topic (for sub-indices)
99115
_topic = metadata.get("Topic", "").lower().split(",")
100116
self.topic: set[str] = {topic for topic_raw in _topic if (topic := topic_raw.strip())}
@@ -157,6 +173,7 @@ def full_details(self) -> dict[str, str | int | Sequence[str]]:
157173
"number": self.number,
158174
"title": self.title,
159175
"authors": ", ".join(self._author_names),
176+
"sponsor": self.sponsor,
160177
"discussions_to": self.discussions_to,
161178
"status": self.status,
162179
"type": self.pep_type,
@@ -182,25 +199,32 @@ def _raise_pep_error(pep: PEP, msg: str, pep_num: bool = False) -> None:
182199

183200
jr_placeholder = ",Jr"
184201

185-
186-
def _parse_author(data: str) -> list[_Author]:
187-
"""Return a list of author names and emails."""
188-
189-
author_list = []
202+
def _parse_participants(data: str) -> tuple[str, str]:
203+
participants_list = []
190204
data = (data.replace("\n", " ")
191205
.replace(", Jr", jr_placeholder)
192206
.rstrip().removesuffix(","))
193-
for author_email in data.split(", "):
194-
if ' <' in author_email:
195-
author, email = author_email.removesuffix(">").split(" <")
207+
for participant_email in data.split(", "):
208+
if ' <' in participant_email:
209+
participant, email = participant_email.removesuffix(">").split(" <")
196210
else:
197-
author, email = author_email, ""
211+
participant, email = participant_email, ""
198212

199-
author = author.strip()
200-
if author == "":
213+
participant = participant.strip()
214+
if participant == "":
201215
raise ValueError("Name is empty!")
202216

203-
author = author.replace(jr_placeholder, ", Jr")
217+
participant = participant.replace(jr_placeholder, ", Jr")
204218
email = email.lower()
205-
author_list.append(_Author(author, email))
206-
return author_list
219+
participants_list.append((participant, email))
220+
return participants_list
221+
222+
223+
224+
def _parse_author(data: str) -> list[_Author]:
225+
"""Return a list of author names and emails."""
226+
return [_Author(author, email) for author, email in _parse_participants(data)]
227+
228+
def _parse_sponsor(data: str) -> _Sponsor:
229+
"""Return sponsor name and email"""
230+
return _Sponsor(*_parse_participants(data)[0])

0 commit comments

Comments
 (0)