最新の sphinxext を移植.
@@ -5,7 +5,7 @@ | ||
5 | 5 | |
6 | 6 | Sphinx extension with Python doc-specific markup. |
7 | 7 | |
8 | - :copyright: 2008 by Georg Brandl. | |
8 | + :copyright: 2008, 2009 by Georg Brandl. | |
9 | 9 | :license: Python license. |
10 | 10 | """ |
11 | 11 |
@@ -20,7 +20,22 @@ | ||
20 | 20 | Body.enum.converters['lowerroman'] = \ |
21 | 21 | Body.enum.converters['upperroman'] = lambda x: None |
22 | 22 | |
23 | +# monkey-patch HTML translator to give versionmodified paragraphs a class | |
24 | +def new_visit_versionmodified(self, node): | |
25 | + self.body.append(self.starttag(node, 'p', CLASS=node['type'])) | |
26 | + text = versionlabels[node['type']] % node['version'] | |
27 | + if len(node): | |
28 | + text += ': ' | |
29 | + else: | |
30 | + text += '.' | |
31 | + self.body.append('<span class="versionmodified">%s</span>' % text) | |
23 | 32 | |
33 | +from sphinx.writers.html import HTMLTranslator | |
34 | +from sphinx.locale import versionlabels | |
35 | +HTMLTranslator.visit_versionmodified = new_visit_versionmodified | |
36 | + | |
37 | +# Support for marking up and linking to bugs.python.org issues | |
38 | + | |
24 | 39 | def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): |
25 | 40 | issue = utils.unescape(text) |
26 | 41 | text = 'issue ' + issue |
@@ -28,6 +43,34 @@ | ||
28 | 43 | return [refnode], [] |
29 | 44 | |
30 | 45 | |
46 | +# Support for marking up implementation details | |
47 | + | |
48 | +from sphinx.util.compat import Directive | |
49 | + | |
50 | +class ImplementationDetail(Directive): | |
51 | + | |
52 | + has_content = True | |
53 | + required_arguments = 0 | |
54 | + optional_arguments = 1 | |
55 | + final_argument_whitespace = True | |
56 | + | |
57 | + def run(self): | |
58 | + pnode = nodes.compound(classes=['impl-detail']) | |
59 | + content = self.content | |
60 | + add_text = nodes.strong('CPython implementation detail:', | |
61 | + 'CPython implementation detail:') | |
62 | + if self.arguments: | |
63 | + n, m = self.state.inline_text(self.arguments[0], self.lineno) | |
64 | + pnode.append(nodes.paragraph('', '', *(n + m))) | |
65 | + self.state.nested_parse(content, self.content_offset, pnode) | |
66 | + if pnode.children and isinstance(pnode[0], nodes.paragraph): | |
67 | + pnode[0].insert(0, add_text) | |
68 | + pnode[0].insert(1, nodes.Text(' ')) | |
69 | + else: | |
70 | + pnode.insert(0, nodes.paragraph('', '', add_text)) | |
71 | + return [pnode] | |
72 | + | |
73 | + | |
31 | 74 | # Support for building "topic help" for pydoc |
32 | 75 | |
33 | 76 | pydoc_topic_labels = [ |
@@ -59,7 +102,11 @@ | ||
59 | 102 | try: |
60 | 103 | from sphinx.builders import Builder |
61 | 104 | except ImportError: |
105 | + # using Sphinx < 0.6, which has a different package layout | |
62 | 106 | from sphinx.builder import Builder |
107 | + # monkey-patch toctree directive to accept (and ignore) the :numbered: flag | |
108 | + from sphinx.directives.other import toctree_directive | |
109 | + toctree_directive.options['numbered'] = toctree_directive.options['glob'] | |
63 | 110 | |
64 | 111 | try: |
65 | 112 | from sphinx.writers.text import TextWriter |
@@ -101,10 +148,12 @@ | ||
101 | 148 | finally: |
102 | 149 | f.close() |
103 | 150 | |
151 | + | |
104 | 152 | # Support for checking for suspicious markup |
105 | 153 | |
106 | 154 | import suspicious |
107 | 155 | |
156 | + | |
108 | 157 | # Support for documenting Opcodes |
109 | 158 | |
110 | 159 | import re |
@@ -127,7 +176,9 @@ | ||
127 | 176 | |
128 | 177 | def setup(app): |
129 | 178 | app.add_role('issue', issue_role) |
179 | + app.add_directive('impl-detail', ImplementationDetail) | |
130 | 180 | app.add_builder(PydocTopicsBuilder) |
131 | 181 | app.add_builder(suspicious.CheckSuspiciousMarkupBuilder) |
132 | 182 | app.add_description_unit('opcode', 'opcode', '%s (opcode)', |
133 | 183 | parse_opcode_signature) |
184 | + app.add_description_unit('2to3fixer', '2to3fixer', '%s (2to3 fixer)') |
@@ -164,7 +164,7 @@ | ||
164 | 164 | except IOError: return |
165 | 165 | for i, row in enumerate(csv.reader(f)): |
166 | 166 | if len(row) != 4: |
167 | - raise ValueError, "wrong format in %s, line %d: %s" % (filename, i+1, row) | |
167 | + raise ValueError("wrong format in %s, line %d: %s" % (filename, i+1, row)) | |
168 | 168 | docname, lineno, issue, text = row |
169 | 169 | docname = docname.decode('utf-8') |
170 | 170 | if lineno: lineno = int(lineno) |