-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Infra: Add Sponsor to the PEPs API #4804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Secrus
wants to merge
1
commit into
python:main
Choose a base branch
from
Secrus:add-sponsor-to-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+42
−18
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -18,11 +18,24 @@ | |||||||||||||||||||||||||||||||||||||||||
| from pep_sphinx_extensions.pep_zero_generator.errors import PEPError | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @dataclasses.dataclass(order=True, frozen=True) | ||||||||||||||||||||||||||||||||||||||||||
| class _Author: | ||||||||||||||||||||||||||||||||||||||||||
| _frozen_ordered = dataclasses.dataclass(order=True, frozen=True) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @_frozen_ordered | ||||||||||||||||||||||||||||||||||||||||||
| class _Participant: | ||||||||||||||||||||||||||||||||||||||||||
| """Represent PEP participant.""" | ||||||||||||||||||||||||||||||||||||||||||
| full_name: str # The participant's name. | ||||||||||||||||||||||||||||||||||||||||||
| email: str # The participant's email address. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @_frozen_ordered | ||||||||||||||||||||||||||||||||||||||||||
| class _Author(_Participant): | ||||||||||||||||||||||||||||||||||||||||||
| """Represent PEP authors.""" | ||||||||||||||||||||||||||||||||||||||||||
| full_name: str # The author's name. | ||||||||||||||||||||||||||||||||||||||||||
| email: str # The author's email address. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @_frozen_ordered | ||||||||||||||||||||||||||||||||||||||||||
| class _Sponsor(_Participant): | ||||||||||||||||||||||||||||||||||||||||||
| """Represent PEP sponsors.""" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| class PEP: | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -95,6 +108,9 @@ def __init__(self, filename: Path): | |||||||||||||||||||||||||||||||||||||||||
| if not self.authors: | ||||||||||||||||||||||||||||||||||||||||||
| raise _raise_pep_error(self, "no authors found", pep_num=True) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Parse PEP sponsors | ||||||||||||||||||||||||||||||||||||||||||
| self.sponsor: str | None = _parse_sponsor(metadata["Sponsor"]).full_name if metadata["Sponsor"] else None | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| # Topic (for sub-indices) | ||||||||||||||||||||||||||||||||||||||||||
| _topic = metadata.get("Topic", "").lower().split(",") | ||||||||||||||||||||||||||||||||||||||||||
| 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]]: | |||||||||||||||||||||||||||||||||||||||||
| "number": self.number, | ||||||||||||||||||||||||||||||||||||||||||
| "title": self.title, | ||||||||||||||||||||||||||||||||||||||||||
| "authors": ", ".join(self._author_names), | ||||||||||||||||||||||||||||||||||||||||||
| "sponsor": self.sponsor, | ||||||||||||||||||||||||||||||||||||||||||
| "discussions_to": self.discussions_to, | ||||||||||||||||||||||||||||||||||||||||||
| "status": self.status, | ||||||||||||||||||||||||||||||||||||||||||
| "type": self.pep_type, | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -182,25 +199,32 @@ def _raise_pep_error(pep: PEP, msg: str, pep_num: bool = False) -> None: | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| jr_placeholder = ",Jr" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _parse_author(data: str) -> list[_Author]: | ||||||||||||||||||||||||||||||||||||||||||
| """Return a list of author names and emails.""" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| author_list = [] | ||||||||||||||||||||||||||||||||||||||||||
| def _parse_participants(data: str) -> tuple[str, str]: | ||||||||||||||||||||||||||||||||||||||||||
| participants_list = [] | ||||||||||||||||||||||||||||||||||||||||||
| data = (data.replace("\n", " ") | ||||||||||||||||||||||||||||||||||||||||||
| .replace(", Jr", jr_placeholder) | ||||||||||||||||||||||||||||||||||||||||||
| .rstrip().removesuffix(",")) | ||||||||||||||||||||||||||||||||||||||||||
| for author_email in data.split(", "): | ||||||||||||||||||||||||||||||||||||||||||
| if ' <' in author_email: | ||||||||||||||||||||||||||||||||||||||||||
| author, email = author_email.removesuffix(">").split(" <") | ||||||||||||||||||||||||||||||||||||||||||
| for participant_email in data.split(", "): | ||||||||||||||||||||||||||||||||||||||||||
| if ' <' in participant_email: | ||||||||||||||||||||||||||||||||||||||||||
| participant, email = participant_email.removesuffix(">").split(" <") | ||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||
| author, email = author_email, "" | ||||||||||||||||||||||||||||||||||||||||||
| participant, email = participant_email, "" | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| author = author.strip() | ||||||||||||||||||||||||||||||||||||||||||
| if author == "": | ||||||||||||||||||||||||||||||||||||||||||
| participant = participant.strip() | ||||||||||||||||||||||||||||||||||||||||||
| if participant == "": | ||||||||||||||||||||||||||||||||||||||||||
| raise ValueError("Name is empty!") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| author = author.replace(jr_placeholder, ", Jr") | ||||||||||||||||||||||||||||||||||||||||||
| participant = participant.replace(jr_placeholder, ", Jr") | ||||||||||||||||||||||||||||||||||||||||||
| email = email.lower() | ||||||||||||||||||||||||||||||||||||||||||
| author_list.append(_Author(author, email)) | ||||||||||||||||||||||||||||||||||||||||||
| return author_list | ||||||||||||||||||||||||||||||||||||||||||
| participants_list.append((participant, email)) | ||||||||||||||||||||||||||||||||||||||||||
| return participants_list | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _parse_author(data: str) -> list[_Author]: | ||||||||||||||||||||||||||||||||||||||||||
| """Return a list of author names and emails.""" | ||||||||||||||||||||||||||||||||||||||||||
| return [_Author(author, email) for author, email in _parse_participants(data)] | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| def _parse_sponsor(data: str) -> _Sponsor: | ||||||||||||||||||||||||||||||||||||||||||
| """Return sponsor name and email""" | ||||||||||||||||||||||||||||||||||||||||||
| return _Sponsor(*_parse_participants(data)[0]) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+221
to
+230
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Formatting nits
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider not creating an alias here, obeying the locality of behavior rule (LoB) and keeping separate classes slightly more self-contained. Consider using
dataclasses.field(doc=...).