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
|
2008-12-20 20:16:13 -04:00
|
|
|
|
Merged revisions 68288-68291,68325-68326,68338,68388,68393,68423 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68288 | benjamin.peterson | 2009-01-03 18:39:07 -0600 (Sat, 03 Jan 2009) | 1 line
only check the actual compile() call for a SyntaxError
................
r68289 | georg.brandl | 2009-01-04 02:26:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Test commit.
................
r68290 | georg.brandl | 2009-01-04 04:23:49 -0600 (Sun, 04 Jan 2009) | 4 lines
Add "suspicious" builder which finds leftover markup in the HTML files.
Patch by Gabriel Genellina.
................
r68291 | georg.brandl | 2009-01-04 04:24:09 -0600 (Sun, 04 Jan 2009) | 2 lines
Fix two issues found by the suspicious builder.
................
r68325 | benjamin.peterson | 2009-01-04 16:00:18 -0600 (Sun, 04 Jan 2009) | 1 line
use Jinja 2.1.1
................
r68326 | georg.brandl | 2009-01-04 16:03:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Update make.bat.
................
r68338 | neal.norwitz | 2009-01-04 21:57:25 -0600 (Sun, 04 Jan 2009) | 1 line
Make sure to checkout any new packages
................
r68388 | benjamin.peterson | 2009-01-07 21:39:46 -0600 (Wed, 07 Jan 2009) | 1 line
string exceptions are gone
................
r68393 | benjamin.peterson | 2009-01-07 22:01:00 -0600 (Wed, 07 Jan 2009) | 1 line
use new sphinx modules
................
r68423 | benjamin.peterson | 2009-01-08 20:13:34 -0600 (Thu, 08 Jan 2009) | 29 lines
Merged revisions 68306-68308,68340,68368,68422 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r68306 | benjamin.peterson | 2009-01-04 12:27:19 -0600 (Sun, 04 Jan 2009) | 1 line
fix_urllib: add mappings for the url parsing functions
........
r68307 | benjamin.peterson | 2009-01-04 12:30:01 -0600 (Sun, 04 Jan 2009) | 1 line
remove duplicated function
........
r68308 | benjamin.peterson | 2009-01-04 12:50:34 -0600 (Sun, 04 Jan 2009) | 1 line
turtle is no longer renamed
........
r68340 | georg.brandl | 2009-01-05 02:11:39 -0600 (Mon, 05 Jan 2009) | 2 lines
Fix undefined locals in parse_tokens().
........
r68368 | benjamin.peterson | 2009-01-06 17:56:10 -0600 (Tue, 06 Jan 2009) | 1 line
fix typo (thanks to Robert Lehmann)
........
r68422 | benjamin.peterson | 2009-01-08 20:01:03 -0600 (Thu, 08 Jan 2009) | 1 line
run the imports fixers after fix_import, so fix_import doesn't try to make stdlib renames into relative imports #4876
........
................
2009-01-08 23:03:23 -04:00
|
|
|
from sphinx.builders import Builder
|
|
|
|
from sphinx.writers.text import TextWriter
|
2008-12-01 19:02:51 -04:00
|
|
|
|
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()
|
|
|
|
|
Merged revisions 68288-68291,68325-68326,68338,68388,68393,68423 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68288 | benjamin.peterson | 2009-01-03 18:39:07 -0600 (Sat, 03 Jan 2009) | 1 line
only check the actual compile() call for a SyntaxError
................
r68289 | georg.brandl | 2009-01-04 02:26:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Test commit.
................
r68290 | georg.brandl | 2009-01-04 04:23:49 -0600 (Sun, 04 Jan 2009) | 4 lines
Add "suspicious" builder which finds leftover markup in the HTML files.
Patch by Gabriel Genellina.
................
r68291 | georg.brandl | 2009-01-04 04:24:09 -0600 (Sun, 04 Jan 2009) | 2 lines
Fix two issues found by the suspicious builder.
................
r68325 | benjamin.peterson | 2009-01-04 16:00:18 -0600 (Sun, 04 Jan 2009) | 1 line
use Jinja 2.1.1
................
r68326 | georg.brandl | 2009-01-04 16:03:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Update make.bat.
................
r68338 | neal.norwitz | 2009-01-04 21:57:25 -0600 (Sun, 04 Jan 2009) | 1 line
Make sure to checkout any new packages
................
r68388 | benjamin.peterson | 2009-01-07 21:39:46 -0600 (Wed, 07 Jan 2009) | 1 line
string exceptions are gone
................
r68393 | benjamin.peterson | 2009-01-07 22:01:00 -0600 (Wed, 07 Jan 2009) | 1 line
use new sphinx modules
................
r68423 | benjamin.peterson | 2009-01-08 20:13:34 -0600 (Thu, 08 Jan 2009) | 29 lines
Merged revisions 68306-68308,68340,68368,68422 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r68306 | benjamin.peterson | 2009-01-04 12:27:19 -0600 (Sun, 04 Jan 2009) | 1 line
fix_urllib: add mappings for the url parsing functions
........
r68307 | benjamin.peterson | 2009-01-04 12:30:01 -0600 (Sun, 04 Jan 2009) | 1 line
remove duplicated function
........
r68308 | benjamin.peterson | 2009-01-04 12:50:34 -0600 (Sun, 04 Jan 2009) | 1 line
turtle is no longer renamed
........
r68340 | georg.brandl | 2009-01-05 02:11:39 -0600 (Mon, 05 Jan 2009) | 2 lines
Fix undefined locals in parse_tokens().
........
r68368 | benjamin.peterson | 2009-01-06 17:56:10 -0600 (Tue, 06 Jan 2009) | 1 line
fix typo (thanks to Robert Lehmann)
........
r68422 | benjamin.peterson | 2009-01-08 20:01:03 -0600 (Thu, 08 Jan 2009) | 1 line
run the imports fixers after fix_import, so fix_import doesn't try to make stdlib renames into relative imports #4876
........
................
2009-01-08 23:03:23 -04:00
|
|
|
# Support for checking for suspicious markup
|
|
|
|
|
|
|
|
import suspicious
|
2008-06-01 18:05:17 -03:00
|
|
|
|
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)
|
Merged revisions 68288-68291,68325-68326,68338,68388,68393,68423 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r68288 | benjamin.peterson | 2009-01-03 18:39:07 -0600 (Sat, 03 Jan 2009) | 1 line
only check the actual compile() call for a SyntaxError
................
r68289 | georg.brandl | 2009-01-04 02:26:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Test commit.
................
r68290 | georg.brandl | 2009-01-04 04:23:49 -0600 (Sun, 04 Jan 2009) | 4 lines
Add "suspicious" builder which finds leftover markup in the HTML files.
Patch by Gabriel Genellina.
................
r68291 | georg.brandl | 2009-01-04 04:24:09 -0600 (Sun, 04 Jan 2009) | 2 lines
Fix two issues found by the suspicious builder.
................
r68325 | benjamin.peterson | 2009-01-04 16:00:18 -0600 (Sun, 04 Jan 2009) | 1 line
use Jinja 2.1.1
................
r68326 | georg.brandl | 2009-01-04 16:03:10 -0600 (Sun, 04 Jan 2009) | 2 lines
Update make.bat.
................
r68338 | neal.norwitz | 2009-01-04 21:57:25 -0600 (Sun, 04 Jan 2009) | 1 line
Make sure to checkout any new packages
................
r68388 | benjamin.peterson | 2009-01-07 21:39:46 -0600 (Wed, 07 Jan 2009) | 1 line
string exceptions are gone
................
r68393 | benjamin.peterson | 2009-01-07 22:01:00 -0600 (Wed, 07 Jan 2009) | 1 line
use new sphinx modules
................
r68423 | benjamin.peterson | 2009-01-08 20:13:34 -0600 (Thu, 08 Jan 2009) | 29 lines
Merged revisions 68306-68308,68340,68368,68422 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r68306 | benjamin.peterson | 2009-01-04 12:27:19 -0600 (Sun, 04 Jan 2009) | 1 line
fix_urllib: add mappings for the url parsing functions
........
r68307 | benjamin.peterson | 2009-01-04 12:30:01 -0600 (Sun, 04 Jan 2009) | 1 line
remove duplicated function
........
r68308 | benjamin.peterson | 2009-01-04 12:50:34 -0600 (Sun, 04 Jan 2009) | 1 line
turtle is no longer renamed
........
r68340 | georg.brandl | 2009-01-05 02:11:39 -0600 (Mon, 05 Jan 2009) | 2 lines
Fix undefined locals in parse_tokens().
........
r68368 | benjamin.peterson | 2009-01-06 17:56:10 -0600 (Tue, 06 Jan 2009) | 1 line
fix typo (thanks to Robert Lehmann)
........
r68422 | benjamin.peterson | 2009-01-08 20:01:03 -0600 (Thu, 08 Jan 2009) | 1 line
run the imports fixers after fix_import, so fix_import doesn't try to make stdlib renames into relative imports #4876
........
................
2009-01-08 23:03:23 -04:00
|
|
|
app.add_builder(suspicious.CheckSuspiciousMarkupBuilder)
|
2008-07-23 12:19:11 -03:00
|
|
|
app.add_description_unit('opcode', 'opcode', '%s (opcode)',
|
|
|
|
parse_opcode_signature)
|