Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3dc5bce

Browse files
authored
[3.12] GH-121970: Extract implementation_detail into a new extension (GH-129663) (#129740)
(cherry picked from commit 4d56c40)
1 parent 895e23d commit 3dc5bce

File tree

4 files changed

+57
-32
lines changed

4 files changed

+57
-32
lines changed

Doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'c_annotations',
2828
'changes',
2929
'glossary_search',
30+
'implementation_detail',
3031
'lexers',
3132
'misc_news',
3233
'pyspecific',
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Support for marking up implementation details."""
2+
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
7+
from docutils import nodes
8+
from sphinx.locale import _ as sphinx_gettext
9+
from sphinx.util.docutils import SphinxDirective
10+
11+
if TYPE_CHECKING:
12+
from sphinx.application import Sphinx
13+
from sphinx.util.typing import ExtensionMetadata
14+
15+
16+
class ImplementationDetail(SphinxDirective):
17+
has_content = True
18+
final_argument_whitespace = True
19+
20+
# This text is copied to templates/dummy.html
21+
label_text = sphinx_gettext("CPython implementation detail:")
22+
23+
def run(self):
24+
self.assert_has_content()
25+
content_nodes = self.parse_content_to_nodes()
26+
27+
# insert our prefix at the start of the first paragraph
28+
first_node = content_nodes[0]
29+
first_node[:0] = [
30+
nodes.strong(self.label_text, self.label_text),
31+
nodes.Text(" "),
32+
]
33+
34+
# create a new compound container node
35+
cnode = nodes.compound("", *content_nodes, classes=["impl-detail"])
36+
self.set_source_info(cnode)
37+
return [cnode]
38+
39+
40+
def setup(app: Sphinx) -> ExtensionMetadata:
41+
app.add_directive("impl-detail", ImplementationDetail)
42+
43+
return {
44+
"version": "1.0",
45+
"parallel_read_safe": True,
46+
"parallel_write_safe": True,
47+
}

Doc/tools/extensions/pyspecific.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,6 @@ def gh_issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
7171
return [refnode], []
7272

7373

74-
# Support for marking up implementation details
75-
76-
class ImplementationDetail(SphinxDirective):
77-
78-
has_content = True
79-
final_argument_whitespace = True
80-
81-
# This text is copied to templates/dummy.html
82-
label_text = sphinx_gettext('CPython implementation detail:')
83-
84-
def run(self):
85-
self.assert_has_content()
86-
pnode = nodes.compound(classes=['impl-detail'])
87-
content = self.content
88-
add_text = nodes.strong(self.label_text, self.label_text)
89-
self.state.nested_parse(content, self.content_offset, pnode)
90-
content = nodes.inline(pnode[0].rawsource, translatable=True)
91-
content.source = pnode[0].source
92-
content.line = pnode[0].line
93-
content += pnode[0].children
94-
pnode[0].replace_self(nodes.paragraph(
95-
'', '', add_text, nodes.Text(' '), content, translatable=False))
96-
return [pnode]
97-
98-
9974
class PyCoroutineMixin(object):
10075
def handle_signature(self, sig, signode):
10176
ret = super(PyCoroutineMixin, self).handle_signature(sig, signode)
@@ -288,7 +263,6 @@ def patch_pairindextypes(app, _env) -> None:
288263
def setup(app):
289264
app.add_role('issue', issue_role)
290265
app.add_role('gh', gh_issue_role)
291-
app.add_directive('impl-detail', ImplementationDetail)
292266
app.add_builder(PydocTopicsBuilder)
293267
app.add_object_type('opcode', 'opcode', '%s (opcode)', parse_opcode_signature)
294268
app.add_object_type('pdbcommand', 'pdbcmd', '%s (pdb command)', parse_pdb_command)

Doc/tools/templates/dummy.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
This file is not an actual template, but used to add some
22
texts in extensions to sphinx.pot file.
33

4-
In extensions/pyspecific.py:
5-
6-
{% trans %}CPython implementation detail:{% endtrans %}
7-
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
8-
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}
9-
104
In extensions/availability.py:
115

126
{% trans %}Availability{% endtrans %}
@@ -27,6 +21,15 @@
2721
{% trans %}Return value: New reference.{% endtrans %}
2822
{% trans %}Return value: Borrowed reference.{% endtrans %}
2923

24+
In extensions/implementation_detail.py:
25+
26+
{% trans %}CPython implementation detail:{% endtrans %}
27+
28+
In extensions/changes.py:
29+
30+
{% trans %}Deprecated since version {deprecated}, will be removed in version {removed}{% endtrans %}
31+
{% trans %}Deprecated since version {deprecated}, removed in version {removed}{% endtrans %}
32+
3033
In docsbuild-scripts, when rewriting indexsidebar.html with actual versions:
3134

3235
{% trans %}in development{% endtrans %}

0 commit comments

Comments
 (0)