2008-04-10 00:06:53 -03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
pyspecific.py
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Sphinx extension with Python doc-specific markup.
|
|
|
|
|
|
|
|
:copyright: 2008 by Georg Brandl.
|
|
|
|
:license: Python license.
|
|
|
|
"""
|
|
|
|
|
|
|
|
ISSUE_URI = 'http://bugs.python.org/issue%s'
|
|
|
|
|
|
|
|
from docutils import nodes, utils
|
|
|
|
|
|
|
|
def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
|
|
|
issue = utils.unescape(text)
|
|
|
|
text = 'issue ' + issue
|
|
|
|
refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue)
|
|
|
|
return [refnode], []
|
|
|
|
|
|
|
|
|
2008-06-01 18:05:17 -03:00
|
|
|
# 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', 'comparisons', 'compound',
|
|
|
|
'context-managers', 'continue', 'conversions', 'customization', 'debugger',
|
|
|
|
'del', 'dict', 'dynamic-features', 'else', 'exceptions', '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', 'raise', 'return', 'sequence-types',
|
|
|
|
'shifting', 'slicings', 'specialattrs', 'specialnames', '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
|
Merged revisions 67348,67355,67359,67362,67364-67365,67367-67368,67398,67423-67424,67432,67440-67441,67444-67445,67454-67455,67457-67458 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67348 | benjamin.peterson | 2008-11-22 20:09:41 -0600 (Sat, 22 Nov 2008) | 1 line
raise a better error
........
r67355 | georg.brandl | 2008-11-23 13:17:25 -0600 (Sun, 23 Nov 2008) | 2 lines
#4392: fix parameter name.
........
r67359 | georg.brandl | 2008-11-23 15:57:30 -0600 (Sun, 23 Nov 2008) | 2 lines
#4399: fix typo.
........
r67362 | gregory.p.smith | 2008-11-23 18:41:43 -0600 (Sun, 23 Nov 2008) | 2 lines
Document PY_SSIZE_T_CLEAN for PyArg_ParseTuple.
........
r67364 | benjamin.peterson | 2008-11-23 19:16:29 -0600 (Sun, 23 Nov 2008) | 2 lines
replace reference to debugger-hooks
........
r67365 | benjamin.peterson | 2008-11-23 22:09:03 -0600 (Sun, 23 Nov 2008) | 1 line
#4396 make the parser module correctly validate the with syntax
........
r67367 | georg.brandl | 2008-11-24 10:16:07 -0600 (Mon, 24 Nov 2008) | 2 lines
Fix typo.
........
r67368 | georg.brandl | 2008-11-24 13:56:47 -0600 (Mon, 24 Nov 2008) | 2 lines
#4404: make clear what "path" is.
........
r67398 | benjamin.peterson | 2008-11-26 11:39:17 -0600 (Wed, 26 Nov 2008) | 1 line
fix typo in sqlite3 docs
........
r67423 | jesse.noller | 2008-11-28 12:59:35 -0600 (Fri, 28 Nov 2008) | 2 lines
issue4238: bsd support for cpu_count
........
r67424 | christian.heimes | 2008-11-28 13:33:33 -0600 (Fri, 28 Nov 2008) | 1 line
Retain copyright of processing examples. This was requested by a Debian maintainer during packaging of the multiprocessing package for 2.4/2.5
........
r67432 | benjamin.peterson | 2008-11-28 17:18:46 -0600 (Fri, 28 Nov 2008) | 1 line
SVN format 9 is the same it seems
........
r67440 | jeremy.hylton | 2008-11-28 17:42:59 -0600 (Fri, 28 Nov 2008) | 4 lines
Move definition int sval into branch of ifdef where it is used.
Otherwise, you get a warning about an undefined variable.
........
r67441 | jeremy.hylton | 2008-11-28 18:09:16 -0600 (Fri, 28 Nov 2008) | 2 lines
Reflow long lines.
........
r67444 | amaury.forgeotdarc | 2008-11-28 20:03:32 -0600 (Fri, 28 Nov 2008) | 2 lines
Fix a small typo in docstring
........
r67445 | benjamin.peterson | 2008-11-29 21:07:33 -0600 (Sat, 29 Nov 2008) | 1 line
StringIO.close() stops you from using the buffer, too
........
r67454 | benjamin.peterson | 2008-11-30 08:43:23 -0600 (Sun, 30 Nov 2008) | 1 line
note the version that works
........
r67455 | martin.v.loewis | 2008-11-30 13:28:27 -0600 (Sun, 30 Nov 2008) | 1 line
Issue #4365: Add crtassem.h constants to the msvcrt module.
........
r67457 | christian.heimes | 2008-11-30 15:16:28 -0600 (Sun, 30 Nov 2008) | 1 line
w# requires Py_ssize_t
........
r67458 | benjamin.peterson | 2008-11-30 15:46:16 -0600 (Sun, 30 Nov 2008) | 1 line
fix pyspecific extensions that were broken by Sphinx's grand renaming
........
2008-11-30 18:46:23 -04:00
|
|
|
from sphinx.writers.text import TextWriter
|
2008-06-01 18:05:17 -03:00
|
|
|
|
|
|
|
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] = str(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()
|
|
|
|
|
|
|
|
|
2008-07-23 12:19:11 -03:00
|
|
|
# Support for documenting Opcodes
|
|
|
|
|
|
|
|
import re
|
|
|
|
from sphinx import addnodes
|
|
|
|
|
|
|
|
opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)\s*\((.*)\)')
|
|
|
|
|
|
|
|
def parse_opcode_signature(env, sig, signode):
|
|
|
|
"""Transform an opcode signature into RST nodes."""
|
|
|
|
m = opcode_sig_re.match(sig)
|
|
|
|
if m is None:
|
|
|
|
raise ValueError
|
|
|
|
opname, arglist = m.groups()
|
|
|
|
signode += addnodes.desc_name(opname, opname)
|
|
|
|
paramlist = addnodes.desc_parameterlist()
|
|
|
|
signode += paramlist
|
|
|
|
paramlist += addnodes.desc_parameter(arglist, arglist)
|
|
|
|
return opname.strip()
|
|
|
|
|
|
|
|
|
2008-04-10 00:06:53 -03:00
|
|
|
def setup(app):
|
|
|
|
app.add_role('issue', issue_role)
|
2008-06-01 18:05:17 -03:00
|
|
|
app.add_builder(PydocTopicsBuilder)
|
2008-07-23 12:19:11 -03:00
|
|
|
app.add_description_unit('opcode', 'opcode', '%s (opcode)',
|
|
|
|
parse_opcode_signature)
|