Skip to content
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

Infra: Add Python version to PEP 0 tables #3434

Merged
merged 9 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pep_sphinx_extensions/pep_theme/static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,17 @@ table td + td {
}
/* Common column widths for PEP status tables */
table.pep-zero-table tr td:nth-child(1) {
width: 5.5%;
width: 5%;
}
table.pep-zero-table tr td:nth-child(2) {
width: 6.5%;
width: 7%;
}
table.pep-zero-table tr td:nth-child(3),
table.pep-zero-table tr td:nth-child(4){
width: 44%;
width: 41%;
}
table.pep-zero-table tr td:nth-child(5) {
width: 6%;
}
/* Authors & Sponsors table */
#authors-owners table td,
Expand Down
2 changes: 2 additions & 0 deletions pep_sphinx_extensions/pep_zero_generator/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def details(self) -> dict[str, str | int]:
"shorthand": self.shorthand,
# the author list as a comma-separated with only last names
"authors": ", ".join(author.full_name for author in self.authors),
# The targeted Python-Version (if present) or the empty string
"python_version": self.python_version or "",
hugovk marked this conversation as resolved.
Show resolved Hide resolved
}

@property
Expand Down
40 changes: 30 additions & 10 deletions pep_sphinx_extensions/pep_zero_generator/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,22 @@
self.output.append(author_table_separator)

def emit_pep_row(
self, *, shorthand: str, number: int, title: str, authors: str
self,
*,
shorthand: str,
number: int,
title: str,
authors: str,
python_version: str | None = None,
) -> None:
self.emit_text(f" * - {shorthand}")
self.emit_text(f" - :pep:`{number} <{number}>`")
self.emit_text(f" - :pep:`{title.replace('`', '')} <{number}>`")
self.emit_text(f" - {authors}")
if python_version is not None:
self.emit_text(f" - {python_version}")

Check warning on line 90 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L89-L90

Added lines #L89 - L90 were not covered by tests

def emit_column_headers(self) -> None:
def emit_column_headers(self, *, include_version=True) -> None:
"""Output the column headers for the PEP indices."""
self.emit_text(".. list-table::")
self.emit_text(" :header-rows: 1")
Expand All @@ -92,6 +100,8 @@
self.emit_text(" - PEP")
self.emit_text(" - Title")
self.emit_text(" - Authors")
if include_version:
self.emit_text(" - ") # for Python-Version

Check warning on line 104 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L103-L104

Added lines #L103 - L104 were not covered by tests

def emit_title(self, text: str, *, symbol: str = "=") -> None:
self.output.append(text)
Expand All @@ -101,17 +111,25 @@
def emit_subtitle(self, text: str) -> None:
self.emit_title(text, symbol="-")

def emit_table(self, peps: list[PEP]) -> None:
include_version = any(pep.details["python_version"] for pep in peps)
self.emit_column_headers(include_version=include_version)
for pep in peps:
details = pep.details
if not include_version:
details.pop("python_version")
self.emit_pep_row(**details)

Check warning on line 121 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L115-L121

Added lines #L115 - L121 were not covered by tests

def emit_pep_category(self, category: str, peps: list[PEP]) -> None:
self.emit_subtitle(category)
self.emit_column_headers()
for pep in peps:
self.emit_pep_row(**pep.details)
self.emit_table(peps)

Check warning on line 125 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L125

Added line #L125 was not covered by tests
# list-table must have at least one body row
if len(peps) == 0:
self.emit_text(" * -")
self.emit_text(" -")
self.emit_text(" -")
self.emit_text(" -")
self.emit_text(" -")

Check warning on line 132 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L132

Added line #L132 was not covered by tests
self.emit_newline()

def write_pep0(
Expand Down Expand Up @@ -180,19 +198,21 @@

# PEPs by number
self.emit_title("Numerical Index")
self.emit_column_headers()
for pep in peps:
self.emit_pep_row(**pep.details)
self.emit_table(peps)

Check warning on line 201 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L201

Added line #L201 was not covered by tests

self.emit_newline()

# Reserved PEP numbers
if is_pep0:
self.emit_title("Reserved PEP Numbers")
self.emit_column_headers()
self.emit_column_headers(include_version=False)

Check warning on line 208 in pep_sphinx_extensions/pep_zero_generator/writer.py

View check run for this annotation

Codecov / codecov/patch

pep_sphinx_extensions/pep_zero_generator/writer.py#L208

Added line #L208 was not covered by tests
for number, claimants in sorted(self.RESERVED.items()):
self.emit_pep_row(
shorthand="", number=number, title="RESERVED", authors=claimants
shorthand="",
number=number,
title="RESERVED",
authors=claimants,
python_version=None,
)

self.emit_newline()
Expand Down
36 changes: 28 additions & 8 deletions pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,35 @@ def test_pep_equal():
assert pep_a == pep_b


def test_pep_details(monkeypatch):
pep8 = parser.PEP(PEP_ROOT / "pep-0008.rst")
@pytest.mark.parametrize(
("test_input", "expected"),
[
(
"pep-0008.rst",
{
"authors": "Guido van Rossum, Barry Warsaw, Nick Coghlan",
"number": 8,
"shorthand": ":abbr:`PA (Process, Active)`",
"title": "Style Guide for Python Code",
"python_version": "",
},
),
(
"pep-0719.rst",
{
"authors": "Thomas Wouters",
"number": 719,
"shorthand": ":abbr:`IA (Informational, Active)`",
"title": "Python 3.13 Release Schedule",
"python_version": "3.13",
},
),
],
)
def test_pep_details(test_input, expected):
pep = parser.PEP(PEP_ROOT / test_input)

assert pep8.details == {
"authors": "Guido van Rossum, Barry Warsaw, Nick Coghlan",
"number": 8,
"shorthand": ":abbr:`PA (Process, Active)`",
"title": "Style Guide for Python Code",
}
assert pep.details == expected


@pytest.mark.parametrize(
Expand Down