summaryrefslogtreecommitdiffstats
path: root/Doc/tools/sphinxext
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2008-06-01 20:33:55 (GMT)
committerGeorg Brandl <georg@python.org>2008-06-01 20:33:55 (GMT)
commit681001e11ba164c67a42251bd2bcee2b260188c3 (patch)
treef15be52edbba69f75a919b6838980c002a640e0e /Doc/tools/sphinxext
parent0b9aaa98a0bdf90684aeaa13bb252f68da401e4c (diff)
downloadcpython-681001e11ba164c67a42251bd2bcee2b260188c3.zip
cpython-681001e11ba164c67a42251bd2bcee2b260188c3.tar.gz
cpython-681001e11ba164c67a42251bd2bcee2b260188c3.tar.bz2
Generate pydoc's topic help from the reST docs via Sphinx'
new text writer.
Diffstat (limited to 'Doc/tools/sphinxext')
-rw-r--r--Doc/tools/sphinxext/pyspecific.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/Doc/tools/sphinxext/pyspecific.py b/Doc/tools/sphinxext/pyspecific.py
index f7c0daa..568a6a1 100644
--- a/Doc/tools/sphinxext/pyspecific.py
+++ b/Doc/tools/sphinxext/pyspecific.py
@@ -20,5 +20,71 @@ def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
return [refnode], []
+# Support for building "topic help" for pydoc
+
+pydoc_topic_labels = [
+ 'assert', 'assignment', 'atom-identifiers', 'atom-literals',
+ 'attribute-access', 'attribute-references', 'augassign', 'binary',
+ 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object',
+ 'bltin-file-objects', 'bltin-null-object', 'bltin-type-objects', 'booleans',
+ 'break', 'callable-types', 'calls', 'class', 'coercion-rules',
+ 'comparisons', 'compound', 'context-managers', 'continue', 'conversions',
+ 'customization', 'debugger', 'del', 'dict', 'dynamic-features', 'else',
+ 'exceptions', 'exec', 'execmodel', 'exprlists', 'floating', 'for',
+ 'formatstrings', 'function', 'global', 'id-classes', 'identifiers', 'if',
+ 'imaginary', 'import', 'in', 'integers', 'lambda', 'lists', 'naming',
+ 'numbers', 'numeric-types', 'objects', 'operator-summary', 'pass', 'power',
+ 'print', 'raise', 'return', 'sequence-methods', 'sequence-types',
+ 'shifting', 'slicings', 'specialattrs', 'specialnames',
+ 'string-conversions', 'string-methods', 'strings', 'subscriptions', 'truth',
+ 'try', 'types', 'typesfunctions', 'typesmapping', 'typesmethods',
+ 'typesmodules', 'typesseq', 'typesseq-mutable', 'unary', 'while', 'with',
+ 'yield'
+]
+
+from os import path
+from time import asctime
+from pprint import pformat
+from docutils.io import StringOutput
+from docutils.utils import new_document
+from sphinx.builder import Builder
+from sphinx.textwriter import TextWriter
+
+class PydocTopicsBuilder(Builder):
+ name = 'pydoc-topics'
+
+ def init(self):
+ self.topics = {}
+
+ def get_outdated_docs(self):
+ return 'all pydoc topics'
+
+ def get_target_uri(self, docname, typ=None):
+ return '' # no URIs
+
+ def write(self, *ignored):
+ writer = TextWriter(self)
+ for label in self.status_iterator(pydoc_topic_labels, 'building topics... '):
+ if label not in self.env.labels:
+ self.warn('label %r not in documentation' % label)
+ continue
+ docname, labelid, sectname = self.env.labels[label]
+ doctree = self.env.get_and_resolve_doctree(docname, self)
+ document = new_document('<section node>')
+ document.append(doctree.ids[labelid])
+ destination = StringOutput(encoding='utf-8')
+ writer.write(document, destination)
+ self.topics[label] = writer.output
+
+ def finish(self):
+ f = open(path.join(self.outdir, 'pydoc_topics.py'), 'w')
+ try:
+ f.write('# Autogenerated by Sphinx on %s\n' % asctime())
+ f.write('topics = ' + pformat(self.topics) + '\n')
+ finally:
+ f.close()
+
+
def setup(app):
app.add_role('issue', issue_role)
+ app.add_builder(PydocTopicsBuilder)