-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Infra: Add new directives to point to PEP's canonical content #2702
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
CAM-Gerlach
merged 6 commits into
python:main
from
CAM-Gerlach:infra-add-canonical-link-directive
Aug 3, 2022
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
452eff8
Infra: Add new roles to point readers to a PEP's canonical content
CAM-Gerlach e2cda20
Infra: Clean up default link title & condition check in canonical dir…
CAM-Gerlach 3f50ab6
Infra: Rename and refactor canonical ref directive to inject reST links
CAM-Gerlach 1a9162e
Infra: Add intersphinx support for Python docs and PyPUG
CAM-Gerlach 786cf33
PEP 12: Add new section documenting canonical directives & intersphinx
CAM-Gerlach debdfd9
Infra: Split banner preface into two sentances & use logical line breaks
CAM-Gerlach 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
100 changes: 100 additions & 0 deletions
100
pep_sphinx_extensions/pep_processor/parsing/pep_canonical_content_directive.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """Roles to insert custom admonitions pointing readers to canonical content.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from docutils import nodes | ||
| from docutils.parsers import rst | ||
|
|
||
|
|
||
| class CanonicalContent(rst.Directive): | ||
| """Insert an admonition pointing readers to a PEP's canonical content.""" | ||
|
|
||
| has_content = True | ||
| required_arguments = 0 | ||
| optional_arguments = 2 | ||
| final_argument_whitespace = True | ||
| option_spec = {} | ||
|
|
||
| default_canonical_link_title = "the Python Docs" | ||
| default_canonical_link_uri = "https://docs.python.org/" | ||
| generic_canonical_link_title = "this link" | ||
| use_default_link = True | ||
|
|
||
| admonition_pre_template = ( | ||
| "This PEP is a historical document; the up-to-date, canonical " | ||
| "documentation can now be found at `{link_title} <{link_uri}>`__." | ||
| ) | ||
| admonition_pre_text = ( | ||
| "This PEP is a historical document; the up-to-date, canonical " | ||
| "documentation can now be found elsewhere." | ||
| ) | ||
| admonition_post_text = ( | ||
| "See :pep:`1` for how to propose changes." | ||
| ) | ||
|
|
||
|
|
||
| def run(self) -> list[nodes.admonition]: | ||
|
|
||
| if self.arguments or (not self.content and self.use_default_link): | ||
CAM-Gerlach marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if self.arguments: | ||
| link_title = self.generic_canonical_link_title | ||
| link_uri = self.arguments[0] | ||
| if len(self.arguments) >= 2: | ||
| link_title = self.arguments[1] | ||
| else: | ||
| link_title = self.default_canonical_link_title | ||
| link_uri = self.default_canonical_link_uri | ||
|
|
||
| pre_text = self.admonition_pre_template.format( | ||
| link_uri=link_uri, link_title=link_title) | ||
|
|
||
| else: | ||
| pre_text = self.admonition_pre_text | ||
|
|
||
| pre_text_node = nodes.paragraph(pre_text) | ||
| pre_text_node.line = self.lineno | ||
| pre_node, pre_msg = self.state.inline_text(pre_text, self.lineno) | ||
| pre_text_node.extend(pre_node + pre_msg) | ||
|
|
||
| post_text = self.admonition_post_text | ||
| post_text_node = nodes.paragraph(post_text) | ||
| post_text_node.line = self.lineno | ||
| post_node, post_msg = self.state.inline_text(post_text, self.lineno) | ||
| post_text_node.extend(post_node + post_msg) | ||
|
|
||
| source_lines = [pre_text] + list(self.content or []) + [post_text] | ||
| admonition_node = nodes.important( | ||
| "\n".join(source_lines), classes=["canonical-content"]) | ||
|
|
||
| admonition_node.append(pre_text_node) | ||
| if self.content: | ||
| self.state.nested_parse( | ||
| self.content, self.content_offset, admonition_node) | ||
| admonition_node.append(post_text_node) | ||
|
|
||
| return [admonition_node] | ||
|
|
||
|
|
||
| class CanonicalContentPyPA(CanonicalContent): | ||
| """Insert a specialized admonition for PyPA packaging specifications.""" | ||
|
|
||
| generic_canonical_link_title = "packaging" | ||
| use_default_link = False | ||
|
|
||
| admonition_pre_template = ( | ||
| "This PEP is a historical document; the up-to-date, canonical " | ||
| "`{link_title} specification " | ||
| "<https://packaging.python.org/en/latest/specifications/{link_uri}/>`__ " | ||
| "is maintained on the `PyPA specs page " | ||
| "<https://packaging.python.org/en/latest/specifications/index.html>`__." | ||
| ) | ||
| admonition_pre_text = ( | ||
| "This PEP is a historical document; the up-to-date, canonical " | ||
| "specification is maintained on the `PyPA specs page " | ||
| "<https://packaging.python.org/en/latest/specifications/index.html>`__." | ||
| ) | ||
| admonition_post_text = ( | ||
| "See the `PyPA specification update process " | ||
| "<https://www.pypa.io/en/latest/specifications/#handling-fixes-and-other-minor-updates>`__ " | ||
| "for how to propose changes." | ||
| ) | ||
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.