From 656b2dad48044a03d9448df12c6e31f7bd993ac6 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 15 Sep 2023 12:16:34 +0300 Subject: [PATCH 1/9] Add Python version to PEP 0 tables --- .../pep_zero_generator/parser.py | 1 + .../pep_zero_generator/writer.py | 17 +++++++++++++++-- .../tests/pep_zero_generator/test_parser.py | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/parser.py b/pep_sphinx_extensions/pep_zero_generator/parser.py index 193186c74ff..9ba42ffcb67 100644 --- a/pep_sphinx_extensions/pep_zero_generator/parser.py +++ b/pep_sphinx_extensions/pep_zero_generator/parser.py @@ -140,6 +140,7 @@ 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), + "python_version": self.python_version or "", } @property diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index 69a5fe4bc6f..296d5851de7 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -74,12 +74,19 @@ def emit_author_table_separator(self, max_name_len: int) -> None: 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: 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}") + self.emit_text(f" - {python_version}") def emit_column_headers(self) -> None: """Output the column headers for the PEP indices.""" @@ -92,6 +99,7 @@ def emit_column_headers(self) -> None: self.emit_text(" - PEP") self.emit_text(" - Title") self.emit_text(" - Authors") + self.emit_text(" - Python") def emit_title(self, text: str, *, symbol: str = "=") -> None: self.output.append(text) @@ -112,6 +120,7 @@ def emit_pep_category(self, category: str, peps: list[PEP]) -> None: self.emit_text(" -") self.emit_text(" -") self.emit_text(" -") + self.emit_text(" -") self.emit_newline() def write_pep0( @@ -192,7 +201,11 @@ def write_pep0( self.emit_column_headers() 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="", ) self.emit_newline() diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index daeb77c709a..55168cefbc1 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -48,6 +48,7 @@ def test_pep_details(monkeypatch): "number": 8, "shorthand": ":abbr:`PA (Process, Active)`", "title": "Style Guide for Python Code", + "python_version": "", } From 98d7d8ed1396590fbb6210c494afa67a27d466b5 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 15 Sep 2023 12:26:43 +0300 Subject: [PATCH 2/9] Test pep.details with and without a target Python version --- .../tests/pep_zero_generator/test_parser.py | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py index 55168cefbc1..d2bd324ea0b 100644 --- a/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py +++ b/pep_sphinx_extensions/tests/pep_zero_generator/test_parser.py @@ -40,16 +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", - "python_version": "", - } + assert pep.details == expected @pytest.mark.parametrize( From 99e22a07dfc2450349443cbc7b4ac4f56b02045e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 22 Sep 2023 18:52:28 +0300 Subject: [PATCH 3/9] Add a comment Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- pep_sphinx_extensions/pep_zero_generator/parser.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pep_sphinx_extensions/pep_zero_generator/parser.py b/pep_sphinx_extensions/pep_zero_generator/parser.py index 9ba42ffcb67..bd8bf9e6884 100644 --- a/pep_sphinx_extensions/pep_zero_generator/parser.py +++ b/pep_sphinx_extensions/pep_zero_generator/parser.py @@ -140,6 +140,7 @@ 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 "", } From 4ef91fa66239fcdf16a06d91f4df8dd796d9f34a Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Fri, 22 Sep 2023 18:55:02 +0300 Subject: [PATCH 4/9] Leave column header for Python version blank --- pep_sphinx_extensions/pep_zero_generator/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index 296d5851de7..67b45d61552 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -99,7 +99,7 @@ def emit_column_headers(self) -> None: self.emit_text(" - PEP") self.emit_text(" - Title") self.emit_text(" - Authors") - self.emit_text(" - Python") + self.emit_text(" - ") def emit_title(self, text: str, *, symbol: str = "=") -> None: self.output.append(text) From c7cf912e867c12401a52ffcf1f409472a165e09b Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:32:51 +0100 Subject: [PATCH 5/9] Add an explanatory comment --- pep_sphinx_extensions/pep_zero_generator/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index 67b45d61552..42257c5f2e0 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -99,7 +99,7 @@ def emit_column_headers(self) -> None: self.emit_text(" - PEP") self.emit_text(" - Title") self.emit_text(" - Authors") - self.emit_text(" - ") + self.emit_text(" - ") # for Python-Version def emit_title(self, text: str, *, symbol: str = "=") -> None: self.output.append(text) From 961e9e001ad33d544eadde17def48eca3b73b5cb Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Fri, 22 Sep 2023 17:52:41 +0100 Subject: [PATCH 6/9] Adjust table widths --- pep_sphinx_extensions/pep_theme/static/style.css | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pep_sphinx_extensions/pep_theme/static/style.css b/pep_sphinx_extensions/pep_theme/static/style.css index 70e1cbf08bf..36393159ab2 100644 --- a/pep_sphinx_extensions/pep_theme/static/style.css +++ b/pep_sphinx_extensions/pep_theme/static/style.css @@ -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, From ddf6e1e8cc69d2b23af6569ef8e07f7673082ffb Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 27 Sep 2023 17:03:23 +0300 Subject: [PATCH 7/9] Only include Python version column if any exist in table --- .../pep_zero_generator/writer.py | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index 42257c5f2e0..2ff42ea9976 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -80,15 +80,16 @@ def emit_pep_row( number: int, title: str, authors: str, - python_version: 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}") - self.emit_text(f" - {python_version}") + if python_version is not None: + self.emit_text(f" - {python_version}") - 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") @@ -99,7 +100,8 @@ def emit_column_headers(self) -> None: self.emit_text(" - PEP") self.emit_text(" - Title") self.emit_text(" - Authors") - self.emit_text(" - ") # for Python-Version + if include_version: + self.emit_text(" - ") # for Python-Version def emit_title(self, text: str, *, symbol: str = "=") -> None: self.output.append(text) @@ -111,9 +113,13 @@ def emit_subtitle(self, text: str) -> None: def emit_pep_category(self, category: str, peps: list[PEP]) -> None: self.emit_subtitle(category) - self.emit_column_headers() + include_version = any(pep.details["python_version"] for pep in peps) + self.emit_column_headers(include_version=include_version) for pep in peps: - self.emit_pep_row(**pep.details) + details = pep.details + if not include_version: + details.pop("python_version") + self.emit_pep_row(**details) # list-table must have at least one body row if len(peps) == 0: self.emit_text(" * -") @@ -189,23 +195,27 @@ def write_pep0( # PEPs by number self.emit_title("Numerical Index") - self.emit_column_headers() + include_version = any(pep.details["python_version"] for pep in peps) + self.emit_column_headers(include_version=include_version) for pep in peps: - self.emit_pep_row(**pep.details) + details = pep.details + if not include_version: + details.pop("python_version") + self.emit_pep_row(**details) 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) for number, claimants in sorted(self.RESERVED.items()): self.emit_pep_row( shorthand="", number=number, title="RESERVED", authors=claimants, - python_version="", + python_version=None, ) self.emit_newline() From 15809b92ba7d5097e1f9581de3c8314face0e43e Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 27 Sep 2023 17:08:16 +0300 Subject: [PATCH 8/9] Refactor duplicate code into emit_table() --- .../pep_zero_generator/writer.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index 2ff42ea9976..fc311e1f6bf 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -111,8 +111,7 @@ def emit_title(self, text: str, *, symbol: str = "=") -> None: def emit_subtitle(self, text: str) -> None: self.emit_title(text, symbol="-") - def emit_pep_category(self, category: str, peps: list[PEP]) -> None: - self.emit_subtitle(category) + def emit_table(self, peps: list[PEP]): include_version = any(pep.details["python_version"] for pep in peps) self.emit_column_headers(include_version=include_version) for pep in peps: @@ -120,6 +119,10 @@ def emit_pep_category(self, category: str, peps: list[PEP]) -> None: if not include_version: details.pop("python_version") self.emit_pep_row(**details) + + def emit_pep_category(self, category: str, peps: list[PEP]) -> None: + self.emit_subtitle(category) + self.emit_table(peps) # list-table must have at least one body row if len(peps) == 0: self.emit_text(" * -") @@ -195,13 +198,7 @@ def write_pep0( # PEPs by number self.emit_title("Numerical Index") - 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) + self.emit_table(peps) self.emit_newline() From 386cca6bdab8236b89988c53d6059c62266ce406 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Wed, 27 Sep 2023 17:11:33 +0300 Subject: [PATCH 9/9] Add type hint Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- pep_sphinx_extensions/pep_zero_generator/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep_sphinx_extensions/pep_zero_generator/writer.py b/pep_sphinx_extensions/pep_zero_generator/writer.py index fc311e1f6bf..f8232d0ceb0 100644 --- a/pep_sphinx_extensions/pep_zero_generator/writer.py +++ b/pep_sphinx_extensions/pep_zero_generator/writer.py @@ -111,7 +111,7 @@ def emit_title(self, text: str, *, symbol: str = "=") -> None: def emit_subtitle(self, text: str) -> None: self.emit_title(text, symbol="-") - def emit_table(self, peps: list[PEP]): + 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: