Skip to content

Commit 59307a6

Browse files
committed
Revert "pythonGH-121970: Extract pydoc_topics into a new extension (python#129116)"
This reverts commit 01bcf13.
1 parent f9d0531 commit 59307a6

File tree

4 files changed

+17646
-12984
lines changed

4 files changed

+17646
-12984
lines changed

Diff for: Doc/conf.py

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
'issue_role',
3434
'lexers',
3535
'misc_news',
36-
'pydoc_topics',
3736
'pyspecific',
3837
'sphinx.ext.coverage',
3938
'sphinx.ext.doctest',

Diff for: Doc/tools/extensions/pydoc_topics.py

-188
This file was deleted.

Diff for: Doc/tools/extensions/pyspecific.py

+71-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,20 @@
1212
import re
1313
import io
1414
from os import getenv, path
15+
from time import asctime
16+
from pprint import pformat
1517

1618
from docutils import nodes
19+
from docutils.io import StringOutput
1720
from docutils.parsers.rst import directives
18-
from docutils.utils import unescape
21+
from docutils.utils import new_document, unescape
1922
from sphinx import addnodes
23+
from sphinx.builders import Builder
2024
from sphinx.domains.python import PyFunction, PyMethod, PyModule
2125
from sphinx.locale import _ as sphinx_gettext
2226
from sphinx.util.docutils import SphinxDirective
27+
from sphinx.writers.text import TextWriter, TextTranslator
28+
from sphinx.util.display import status_iterator
2329

2430
# Used in conf.py and updated here by python/release-tools/run_release.py
2531
SOURCE_URI = 'https://github.com/python/cpython/tree/main/%s'
@@ -51,6 +57,69 @@ def run(self):
5157
return PyMethod.run(self)
5258

5359

60+
# Support for building "topic help" for pydoc
61+
62+
pydoc_topic_labels = [
63+
'assert', 'assignment', 'assignment-expressions', 'async', 'atom-identifiers',
64+
'atom-literals', 'attribute-access', 'attribute-references', 'augassign', 'await',
65+
'binary', 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
66+
'bltin-null-object', 'bltin-type-objects', 'booleans',
67+
'break', 'callable-types', 'calls', 'class', 'comparisons', 'compound',
68+
'context-managers', 'continue', 'conversions', 'customization', 'debugger',
69+
'del', 'dict', 'dynamic-features', 'else', 'exceptions', 'execmodel',
70+
'exprlists', 'floating', 'for', 'formatstrings', 'function', 'global',
71+
'id-classes', 'identifiers', 'if', 'imaginary', 'import', 'in', 'integers',
72+
'lambda', 'lists', 'naming', 'nonlocal', 'numbers', 'numeric-types',
73+
'objects', 'operator-summary', 'pass', 'power', 'raise', 'return',
74+
'sequence-types', 'shifting', 'slicings', 'specialattrs', 'specialnames',
75+
'string-methods', 'strings', 'subscriptions', 'truth', 'try', 'types',
76+
'typesfunctions', 'typesmapping', 'typesmethods', 'typesmodules',
77+
'typesseq', 'typesseq-mutable', 'unary', 'while', 'with', 'yield'
78+
]
79+
80+
81+
class PydocTopicsBuilder(Builder):
82+
name = 'pydoc-topics'
83+
84+
default_translator_class = TextTranslator
85+
86+
def init(self):
87+
self.topics = {}
88+
self.secnumbers = {}
89+
90+
def get_outdated_docs(self):
91+
return 'all pydoc topics'
92+
93+
def get_target_uri(self, docname, typ=None):
94+
return '' # no URIs
95+
96+
def write(self, *ignored):
97+
writer = TextWriter(self)
98+
for label in status_iterator(pydoc_topic_labels,
99+
'building topics... ',
100+
length=len(pydoc_topic_labels)):
101+
if label not in self.env.domaindata['std']['labels']:
102+
self.env.logger.warning(f'label {label!r} not in documentation')
103+
continue
104+
docname, labelid, sectname = self.env.domaindata['std']['labels'][label]
105+
doctree = self.env.get_and_resolve_doctree(docname, self)
106+
document = new_document('<section node>')
107+
document.append(doctree.ids[labelid])
108+
destination = StringOutput(encoding='utf-8')
109+
writer.write(document, destination)
110+
self.topics[label] = writer.output
111+
112+
def finish(self):
113+
f = open(path.join(self.outdir, 'topics.py'), 'wb')
114+
try:
115+
f.write('# -*- coding: utf-8 -*-\n'.encode('utf-8'))
116+
f.write(('# Autogenerated by Sphinx on %s\n' % asctime()).encode('utf-8'))
117+
f.write('# as part of the release process.\n'.encode('utf-8'))
118+
f.write(('topics = ' + pformat(self.topics) + '\n').encode('utf-8'))
119+
finally:
120+
f.close()
121+
122+
54123
# Support for documenting Opcodes
55124

56125
opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?')
@@ -127,6 +196,7 @@ def patch_pairindextypes(app, _env) -> None:
127196

128197

129198
def setup(app):
199+
app.add_builder(PydocTopicsBuilder)
130200
app.add_object_type('opcode', 'opcode', '%s (opcode)', parse_opcode_signature)
131201
app.add_object_type('pdbcommand', 'pdbcmd', '%s (pdb command)', parse_pdb_command)
132202
app.add_object_type('monitoring-event', 'monitoring-event', '%s (monitoring event)', parse_monitoring_event)

0 commit comments

Comments
 (0)