-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add support for topic indices #2579
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
52779ea
Support subindices
AA-Turner 382bc54
Add Topic: Packaging
AA-Turner 88cf334
Fix lint rule
AA-Turner 4b415dc
Revert peps.json location change (for now!)
AA-Turner ad10433
Fix lint rule (second attempt)
AA-Turner e97e241
Append docnames
AA-Turner 3582a19
Trois
AA-Turner baa91b1
Revert "Add Topic: Packaging"
AA-Turner 9e5cbc3
Fix 0 pages case
AA-Turner 8772b64
Add PEP 609
AA-Turner b5dbc9a
Hugo's comments
AA-Turner 991ba56
One more
AA-Turner a32af64
capitalisation
AA-Turner 57d3ca3
Add note about the topic index
AA-Turner 9289f9d
Merge branch 'main' into subindicies
ambv 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
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 |
---|---|---|
|
@@ -16,3 +16,4 @@ This is an internal Sphinx page; please go to the :doc:`PEP Index <pep-0000>`. | |
|
||
docs/* | ||
pep-* | ||
topic/* |
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Utilities to support sub-indices for PEPs.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from pep_sphinx_extensions.pep_zero_generator import writer | ||
|
||
if TYPE_CHECKING: | ||
from sphinx.environment import BuildEnvironment | ||
|
||
from pep_sphinx_extensions.pep_zero_generator.parser import PEP | ||
|
||
|
||
def update_sphinx(filename: str, text: str, docnames: list[str], env: BuildEnvironment) -> Path: | ||
file_path = Path(f"{filename}.rst").resolve() | ||
file_path.parent.mkdir(parents=True, exist_ok=True) | ||
file_path.write_text(text, encoding="utf-8") | ||
|
||
# Add to files for builder | ||
docnames.append(filename) | ||
# Add to files for writer | ||
env.found_docs.add(filename) | ||
|
||
return file_path | ||
|
||
|
||
def generate_subindices( | ||
subindices: dict[str, str], | ||
peps: list[PEP], | ||
docnames: list[str], | ||
env: BuildEnvironment, | ||
) -> None: | ||
# Create sub index page | ||
generate_topic_contents(docnames, env) | ||
|
||
for subindex, additional_description in subindices.items(): | ||
header_text = f"{subindex.title()} PEPs" | ||
header_line = "#" * len(header_text) | ||
header = header_text + "\n" + header_line + "\n" | ||
|
||
topic = subindex.lower() | ||
filtered_peps = [pep for pep in peps if topic in pep.topic] | ||
subindex_intro = f"""\ | ||
This is the index of all Python Enhancement Proposals (PEPs) labelled | ||
under the '{subindex.title()}' topic. This is a sub-index of :pep:`0`, | ||
the PEP index. | ||
|
||
{additional_description} | ||
""" | ||
subindex_text = writer.PEPZeroWriter().write_pep0( | ||
filtered_peps, header, subindex_intro, is_pep0=False, | ||
) | ||
update_sphinx(f"topic/{subindex}", subindex_text, docnames, env) | ||
|
||
|
||
def generate_topic_contents(docnames: list[str], env: BuildEnvironment): | ||
update_sphinx(f"topic/index", """\ | ||
Topic Index | ||
*********** | ||
|
||
PEPs are indexed by topic on the pages below: | ||
|
||
.. toctree:: | ||
:maxdepth: 1 | ||
:titlesonly: | ||
:glob: | ||
|
||
* | ||
""", docnames, env) |
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
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
3 changes: 1 addition & 2 deletions
3
pep_sphinx_extensions/tests/pep_zero_generator/test_pep_index_generator.py
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
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.