Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 1 | # -*- coding: utf-8 -*- |
| 2 | """ |
| 3 | pyspecific.py |
| 4 | ~~~~~~~~~~~~~ |
| 5 | |
| 6 | Sphinx extension with Python doc-specific markup. |
| 7 | |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 8 | :copyright: 2008-2014 by Georg Brandl. |
Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 9 | :license: Python license. |
| 10 | """ |
| 11 | |
| 12 | ISSUE_URI = 'http://bugs.python.org/issue%s' |
Georg Brandl | 26eb110 | 2012-09-29 09:36:04 +0200 | [diff] [blame] | 13 | SOURCE_URI = 'http://hg.python.org/cpython/file/default/%s' |
Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 14 | |
| 15 | from docutils import nodes, utils |
Georg Brandl | 239990d | 2013-10-12 20:50:21 +0200 | [diff] [blame] | 16 | |
| 17 | import sphinx |
Georg Brandl | 6881886 | 2010-11-06 07:19:35 +0000 | [diff] [blame] | 18 | from sphinx.util.nodes import split_explicit_title |
Georg Brandl | f7b2f36 | 2014-02-16 09:46:36 +0100 | [diff] [blame] | 19 | from sphinx.util.compat import Directive |
Georg Brandl | 239990d | 2013-10-12 20:50:21 +0200 | [diff] [blame] | 20 | from sphinx.writers.html import HTMLTranslator |
| 21 | from sphinx.writers.latex import LaTeXTranslator |
| 22 | from sphinx.locale import versionlabels |
Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 23 | |
Benjamin Peterson | 5c6d787 | 2009-02-06 02:40:07 +0000 | [diff] [blame] | 24 | # monkey-patch reST parser to disable alphabetic and roman enumerated lists |
| 25 | from docutils.parsers.rst.states import Body |
| 26 | Body.enum.converters['loweralpha'] = \ |
| 27 | Body.enum.converters['upperalpha'] = \ |
| 28 | Body.enum.converters['lowerroman'] = \ |
| 29 | Body.enum.converters['upperroman'] = lambda x: None |
| 30 | |
Georg Brandl | f7b2f36 | 2014-02-16 09:46:36 +0100 | [diff] [blame] | 31 | SPHINX11 = sphinx.__version__[:3] < '1.2' |
| 32 | |
| 33 | if SPHINX11: |
Georg Brandl | 239990d | 2013-10-12 20:50:21 +0200 | [diff] [blame] | 34 | # monkey-patch HTML translator to give versionmodified paragraphs a class |
| 35 | def new_visit_versionmodified(self, node): |
| 36 | self.body.append(self.starttag(node, 'p', CLASS=node['type'])) |
| 37 | text = versionlabels[node['type']] % node['version'] |
| 38 | if len(node): |
| 39 | text += ':' |
| 40 | else: |
| 41 | text += '.' |
| 42 | self.body.append('<span class="versionmodified">%s</span> ' % text) |
| 43 | HTMLTranslator.visit_versionmodified = new_visit_versionmodified |
Georg Brandl | ee8783d | 2009-09-16 16:00:31 +0000 | [diff] [blame] | 44 | |
Georg Brandl | 83e51f4 | 2012-10-10 16:45:11 +0200 | [diff] [blame] | 45 | # monkey-patch HTML and LaTeX translators to keep doctest blocks in the |
| 46 | # doctest docs themselves |
| 47 | orig_visit_literal_block = HTMLTranslator.visit_literal_block |
| 48 | def new_visit_literal_block(self, node): |
| 49 | meta = self.builder.env.metadata[self.builder.current_docname] |
| 50 | old_trim_doctest_flags = self.highlighter.trim_doctest_flags |
| 51 | if 'keepdoctest' in meta: |
| 52 | self.highlighter.trim_doctest_flags = False |
| 53 | try: |
| 54 | orig_visit_literal_block(self, node) |
| 55 | finally: |
| 56 | self.highlighter.trim_doctest_flags = old_trim_doctest_flags |
| 57 | |
| 58 | HTMLTranslator.visit_literal_block = new_visit_literal_block |
| 59 | |
| 60 | orig_depart_literal_block = LaTeXTranslator.depart_literal_block |
| 61 | def new_depart_literal_block(self, node): |
| 62 | meta = self.builder.env.metadata[self.curfilestack[-1]] |
| 63 | old_trim_doctest_flags = self.highlighter.trim_doctest_flags |
| 64 | if 'keepdoctest' in meta: |
| 65 | self.highlighter.trim_doctest_flags = False |
| 66 | try: |
| 67 | orig_depart_literal_block(self, node) |
| 68 | finally: |
| 69 | self.highlighter.trim_doctest_flags = old_trim_doctest_flags |
| 70 | |
| 71 | LaTeXTranslator.depart_literal_block = new_depart_literal_block |
Benjamin Peterson | 5c6d787 | 2009-02-06 02:40:07 +0000 | [diff] [blame] | 72 | |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 73 | # Support for marking up and linking to bugs.python.org issues |
| 74 | |
Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 75 | def issue_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): |
| 76 | issue = utils.unescape(text) |
| 77 | text = 'issue ' + issue |
| 78 | refnode = nodes.reference(text, text, refuri=ISSUE_URI % issue) |
| 79 | return [refnode], [] |
| 80 | |
| 81 | |
Georg Brandl | 6881886 | 2010-11-06 07:19:35 +0000 | [diff] [blame] | 82 | # Support for linking to Python source files easily |
| 83 | |
| 84 | def source_role(typ, rawtext, text, lineno, inliner, options={}, content=[]): |
| 85 | has_t, title, target = split_explicit_title(text) |
| 86 | title = utils.unescape(title) |
| 87 | target = utils.unescape(target) |
| 88 | refnode = nodes.reference(title, title, refuri=SOURCE_URI % target) |
| 89 | return [refnode], [] |
| 90 | |
| 91 | |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 92 | # Support for marking up implementation details |
| 93 | |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 94 | class ImplementationDetail(Directive): |
| 95 | |
| 96 | has_content = True |
| 97 | required_arguments = 0 |
| 98 | optional_arguments = 1 |
| 99 | final_argument_whitespace = True |
| 100 | |
| 101 | def run(self): |
| 102 | pnode = nodes.compound(classes=['impl-detail']) |
| 103 | content = self.content |
| 104 | add_text = nodes.strong('CPython implementation detail:', |
| 105 | 'CPython implementation detail:') |
| 106 | if self.arguments: |
| 107 | n, m = self.state.inline_text(self.arguments[0], self.lineno) |
| 108 | pnode.append(nodes.paragraph('', '', *(n + m))) |
| 109 | self.state.nested_parse(content, self.content_offset, pnode) |
| 110 | if pnode.children and isinstance(pnode[0], nodes.paragraph): |
| 111 | pnode[0].insert(0, add_text) |
| 112 | pnode[0].insert(1, nodes.Text(' ')) |
| 113 | else: |
| 114 | pnode.insert(0, nodes.paragraph('', '', add_text)) |
| 115 | return [pnode] |
| 116 | |
| 117 | |
Georg Brandl | 8a1caa2 | 2010-07-29 16:01:11 +0000 | [diff] [blame] | 118 | # Support for documenting decorators |
| 119 | |
| 120 | from sphinx import addnodes |
| 121 | from sphinx.domains.python import PyModulelevel, PyClassmember |
| 122 | |
| 123 | class PyDecoratorMixin(object): |
| 124 | def handle_signature(self, sig, signode): |
| 125 | ret = super(PyDecoratorMixin, self).handle_signature(sig, signode) |
| 126 | signode.insert(0, addnodes.desc_addname('@', '@')) |
| 127 | return ret |
| 128 | |
| 129 | def needs_arglist(self): |
| 130 | return False |
| 131 | |
| 132 | class PyDecoratorFunction(PyDecoratorMixin, PyModulelevel): |
| 133 | def run(self): |
| 134 | # a decorator function is a function after all |
| 135 | self.name = 'py:function' |
| 136 | return PyModulelevel.run(self) |
| 137 | |
| 138 | class PyDecoratorMethod(PyDecoratorMixin, PyClassmember): |
| 139 | def run(self): |
| 140 | self.name = 'py:method' |
| 141 | return PyClassmember.run(self) |
| 142 | |
| 143 | |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 144 | # Support for documenting version of removal in deprecations |
| 145 | |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 146 | class DeprecatedRemoved(Directive): |
| 147 | has_content = True |
| 148 | required_arguments = 2 |
| 149 | optional_arguments = 1 |
| 150 | final_argument_whitespace = True |
| 151 | option_spec = {} |
| 152 | |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 153 | _label = 'Deprecated since version %s, will be removed in version %s' |
| 154 | |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 155 | def run(self): |
| 156 | node = addnodes.versionmodified() |
| 157 | node.document = self.state.document |
| 158 | node['type'] = 'deprecated-removed' |
| 159 | version = (self.arguments[0], self.arguments[1]) |
| 160 | node['version'] = version |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 161 | text = self._label % version |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 162 | if len(self.arguments) == 3: |
| 163 | inodes, messages = self.state.inline_text(self.arguments[2], |
| 164 | self.lineno+1) |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 165 | para = nodes.paragraph(self.arguments[2], '', *inodes) |
| 166 | node.append(para) |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 167 | else: |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 168 | messages = [] |
| 169 | if self.content: |
| 170 | self.state.nested_parse(self.content, self.content_offset, node) |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 171 | if isinstance(node[0], nodes.paragraph) and node[0].rawsource: |
| 172 | content = nodes.inline(node[0].rawsource, translatable=True) |
| 173 | content.source = node[0].source |
| 174 | content.line = node[0].line |
| 175 | content += node[0].children |
| 176 | node[0].replace_self(nodes.paragraph('', '', content)) |
Georg Brandl | f7b2f36 | 2014-02-16 09:46:36 +0100 | [diff] [blame] | 177 | if not SPHINX11: |
| 178 | node[0].insert(0, nodes.inline('', '%s: ' % text, |
| 179 | classes=['versionmodified'])) |
| 180 | elif not SPHINX11: |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 181 | para = nodes.paragraph('', '', |
| 182 | nodes.inline('', '%s.' % text, classes=['versionmodified'])) |
Berker Peksag | eb265ab | 2014-08-22 18:24:29 +0300 | [diff] [blame] | 183 | if len(node): |
| 184 | node.insert(0, para) |
| 185 | else: |
| 186 | node.append(para) |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 187 | env = self.state.document.settings.env |
| 188 | env.note_versionchange('deprecated', version[0], node, self.lineno) |
Georg Brandl | 7ed509a | 2014-01-21 19:20:31 +0100 | [diff] [blame] | 189 | return [node] + messages |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 190 | |
Georg Brandl | f7b2f36 | 2014-02-16 09:46:36 +0100 | [diff] [blame] | 191 | # for Sphinx < 1.2 |
| 192 | versionlabels['deprecated-removed'] = DeprecatedRemoved._label |
| 193 | |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 194 | |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 195 | # Support for including Misc/NEWS |
| 196 | |
| 197 | import re |
| 198 | import codecs |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 199 | |
Georg Brandl | 44d0c21 | 2012-10-01 19:08:50 +0200 | [diff] [blame] | 200 | issue_re = re.compile('([Ii])ssue #([0-9]+)') |
| 201 | whatsnew_re = re.compile(r"(?im)^what's new in (.*?)\??$") |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 202 | |
| 203 | class MiscNews(Directive): |
| 204 | has_content = False |
| 205 | required_arguments = 1 |
| 206 | optional_arguments = 0 |
| 207 | final_argument_whitespace = False |
| 208 | option_spec = {} |
| 209 | |
| 210 | def run(self): |
| 211 | fname = self.arguments[0] |
| 212 | source = self.state_machine.input_lines.source( |
| 213 | self.lineno - self.state_machine.input_offset - 1) |
| 214 | source_dir = path.dirname(path.abspath(source)) |
Georg Brandl | 44d0c21 | 2012-10-01 19:08:50 +0200 | [diff] [blame] | 215 | fpath = path.join(source_dir, fname) |
| 216 | self.state.document.settings.record_dependencies.add(fpath) |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 217 | try: |
Georg Brandl | 44d0c21 | 2012-10-01 19:08:50 +0200 | [diff] [blame] | 218 | fp = codecs.open(fpath, encoding='utf-8') |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 219 | try: |
| 220 | content = fp.read() |
| 221 | finally: |
| 222 | fp.close() |
| 223 | except Exception: |
| 224 | text = 'The NEWS file is not available.' |
| 225 | node = nodes.strong(text, text) |
| 226 | return [node] |
Georg Brandl | 44d0c21 | 2012-10-01 19:08:50 +0200 | [diff] [blame] | 227 | content = issue_re.sub(r'`\1ssue #\2 <http://bugs.python.org/\2>`__', |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 228 | content) |
Georg Brandl | 44d0c21 | 2012-10-01 19:08:50 +0200 | [diff] [blame] | 229 | content = whatsnew_re.sub(r'\1', content) |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 230 | # remove first 3 lines as they are the main heading |
Georg Brandl | 6c47581 | 2012-10-01 19:27:05 +0200 | [diff] [blame] | 231 | lines = ['.. default-role:: obj', ''] + content.splitlines()[3:] |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 232 | self.state_machine.insert_input(lines, fname) |
| 233 | return [] |
| 234 | |
| 235 | |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 236 | # Support for building "topic help" for pydoc |
| 237 | |
| 238 | pydoc_topic_labels = [ |
| 239 | 'assert', 'assignment', 'atom-identifiers', 'atom-literals', |
| 240 | 'attribute-access', 'attribute-references', 'augassign', 'binary', |
| 241 | 'bitwise', 'bltin-code-objects', 'bltin-ellipsis-object', |
Benjamin Peterson | 0d31d58 | 2010-06-06 02:44:41 +0000 | [diff] [blame] | 242 | 'bltin-null-object', 'bltin-type-objects', 'booleans', |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 243 | 'break', 'callable-types', 'calls', 'class', 'comparisons', 'compound', |
| 244 | 'context-managers', 'continue', 'conversions', 'customization', 'debugger', |
| 245 | 'del', 'dict', 'dynamic-features', 'else', 'exceptions', 'execmodel', |
| 246 | 'exprlists', 'floating', 'for', 'formatstrings', 'function', 'global', |
| 247 | 'id-classes', 'identifiers', 'if', 'imaginary', 'import', 'in', 'integers', |
Benjamin Peterson | f5a3d69 | 2010-08-31 14:31:01 +0000 | [diff] [blame] | 248 | 'lambda', 'lists', 'naming', 'nonlocal', 'numbers', 'numeric-types', |
| 249 | 'objects', 'operator-summary', 'pass', 'power', 'raise', 'return', |
| 250 | 'sequence-types', 'shifting', 'slicings', 'specialattrs', 'specialnames', |
| 251 | 'string-methods', 'strings', 'subscriptions', 'truth', 'try', 'types', |
| 252 | 'typesfunctions', 'typesmapping', 'typesmethods', 'typesmodules', |
| 253 | 'typesseq', 'typesseq-mutable', 'unary', 'while', 'with', 'yield' |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 254 | ] |
| 255 | |
| 256 | from os import path |
| 257 | from time import asctime |
| 258 | from pprint import pformat |
| 259 | from docutils.io import StringOutput |
| 260 | from docutils.utils import new_document |
Benjamin Peterson | 6e43fb1 | 2008-12-21 00:16:13 +0000 | [diff] [blame] | 261 | |
Benjamin Peterson | 28d88b4 | 2009-01-09 03:03:23 +0000 | [diff] [blame] | 262 | from sphinx.builders import Builder |
| 263 | from sphinx.writers.text import TextWriter |
Georg Brandl | db6f108 | 2008-12-01 23:02:51 +0000 | [diff] [blame] | 264 | |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 265 | |
| 266 | class PydocTopicsBuilder(Builder): |
| 267 | name = 'pydoc-topics' |
| 268 | |
| 269 | def init(self): |
| 270 | self.topics = {} |
| 271 | |
| 272 | def get_outdated_docs(self): |
| 273 | return 'all pydoc topics' |
| 274 | |
| 275 | def get_target_uri(self, docname, typ=None): |
| 276 | return '' # no URIs |
| 277 | |
| 278 | def write(self, *ignored): |
| 279 | writer = TextWriter(self) |
Benjamin Peterson | 5879d41 | 2009-03-30 14:51:56 +0000 | [diff] [blame] | 280 | for label in self.status_iterator(pydoc_topic_labels, |
| 281 | 'building topics... ', |
| 282 | length=len(pydoc_topic_labels)): |
Georg Brandl | 80ff2ad | 2010-07-31 08:27:46 +0000 | [diff] [blame] | 283 | if label not in self.env.domaindata['std']['labels']: |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 284 | self.warn('label %r not in documentation' % label) |
| 285 | continue |
Georg Brandl | 80ff2ad | 2010-07-31 08:27:46 +0000 | [diff] [blame] | 286 | docname, labelid, sectname = self.env.domaindata['std']['labels'][label] |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 287 | doctree = self.env.get_and_resolve_doctree(docname, self) |
| 288 | document = new_document('<section node>') |
| 289 | document.append(doctree.ids[labelid]) |
| 290 | destination = StringOutput(encoding='utf-8') |
| 291 | writer.write(document, destination) |
Georg Brandl | 50fdcdf | 2012-03-04 16:12:02 +0100 | [diff] [blame] | 292 | self.topics[label] = writer.output.encode('utf-8') |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 293 | |
| 294 | def finish(self): |
Georg Brandl | 5617db8 | 2009-04-27 16:28:57 +0000 | [diff] [blame] | 295 | f = open(path.join(self.outdir, 'topics.py'), 'w') |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 296 | try: |
Georg Brandl | 50fdcdf | 2012-03-04 16:12:02 +0100 | [diff] [blame] | 297 | f.write('# -*- coding: utf-8 -*-\n') |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 298 | f.write('# Autogenerated by Sphinx on %s\n' % asctime()) |
| 299 | f.write('topics = ' + pformat(self.topics) + '\n') |
| 300 | finally: |
| 301 | f.close() |
| 302 | |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 303 | |
Benjamin Peterson | 28d88b4 | 2009-01-09 03:03:23 +0000 | [diff] [blame] | 304 | # Support for checking for suspicious markup |
| 305 | |
| 306 | import suspicious |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 307 | |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 308 | |
Georg Brandl | f0dd6a6 | 2008-07-23 15:19:11 +0000 | [diff] [blame] | 309 | # Support for documenting Opcodes |
| 310 | |
| 311 | import re |
Georg Brandl | f0dd6a6 | 2008-07-23 15:19:11 +0000 | [diff] [blame] | 312 | |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 313 | opcode_sig_re = re.compile(r'(\w+(?:\+\d)?)(?:\s*\((.*)\))?') |
Georg Brandl | f0dd6a6 | 2008-07-23 15:19:11 +0000 | [diff] [blame] | 314 | |
| 315 | def parse_opcode_signature(env, sig, signode): |
| 316 | """Transform an opcode signature into RST nodes.""" |
| 317 | m = opcode_sig_re.match(sig) |
| 318 | if m is None: |
| 319 | raise ValueError |
| 320 | opname, arglist = m.groups() |
| 321 | signode += addnodes.desc_name(opname, opname) |
Georg Brandl | 4833e5b | 2010-07-03 10:41:33 +0000 | [diff] [blame] | 322 | if arglist is not None: |
| 323 | paramlist = addnodes.desc_parameterlist() |
| 324 | signode += paramlist |
| 325 | paramlist += addnodes.desc_parameter(arglist, arglist) |
Georg Brandl | f0dd6a6 | 2008-07-23 15:19:11 +0000 | [diff] [blame] | 326 | return opname.strip() |
| 327 | |
| 328 | |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 329 | # Support for documenting pdb commands |
| 330 | |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 331 | pdbcmd_sig_re = re.compile(r'([a-z()!]+)\s*(.*)') |
| 332 | |
| 333 | # later... |
| 334 | #pdbargs_tokens_re = re.compile(r'''[a-zA-Z]+ | # identifiers |
| 335 | # [.,:]+ | # punctuation |
| 336 | # [\[\]()] | # parens |
| 337 | # \s+ # whitespace |
| 338 | # ''', re.X) |
| 339 | |
| 340 | def parse_pdb_command(env, sig, signode): |
| 341 | """Transform a pdb command signature into RST nodes.""" |
| 342 | m = pdbcmd_sig_re.match(sig) |
| 343 | if m is None: |
| 344 | raise ValueError |
| 345 | name, args = m.groups() |
| 346 | fullname = name.replace('(', '').replace(')', '') |
| 347 | signode += addnodes.desc_name(name, name) |
| 348 | if args: |
| 349 | signode += addnodes.desc_addname(' '+args, ' '+args) |
| 350 | return fullname |
| 351 | |
| 352 | |
Martin v. Löwis | 5680d0c | 2008-04-10 03:06:53 +0000 | [diff] [blame] | 353 | def setup(app): |
| 354 | app.add_role('issue', issue_role) |
Georg Brandl | 6881886 | 2010-11-06 07:19:35 +0000 | [diff] [blame] | 355 | app.add_role('source', source_role) |
Georg Brandl | 495f7b5 | 2009-10-27 15:28:25 +0000 | [diff] [blame] | 356 | app.add_directive('impl-detail', ImplementationDetail) |
Georg Brandl | 281d6ba | 2010-11-12 08:57:12 +0000 | [diff] [blame] | 357 | app.add_directive('deprecated-removed', DeprecatedRemoved) |
Georg Brandl | 6b38daa | 2008-06-01 21:05:17 +0000 | [diff] [blame] | 358 | app.add_builder(PydocTopicsBuilder) |
Benjamin Peterson | 28d88b4 | 2009-01-09 03:03:23 +0000 | [diff] [blame] | 359 | app.add_builder(suspicious.CheckSuspiciousMarkupBuilder) |
Georg Brandl | f0dd6a6 | 2008-07-23 15:19:11 +0000 | [diff] [blame] | 360 | app.add_description_unit('opcode', 'opcode', '%s (opcode)', |
| 361 | parse_opcode_signature) |
Georg Brandl | 02053ee | 2010-07-18 10:11:03 +0000 | [diff] [blame] | 362 | app.add_description_unit('pdbcommand', 'pdbcmd', '%s (pdb command)', |
| 363 | parse_pdb_command) |
Benjamin Peterson | f91df04 | 2009-02-13 02:50:59 +0000 | [diff] [blame] | 364 | app.add_description_unit('2to3fixer', '2to3fixer', '%s (2to3 fixer)') |
Georg Brandl | 8a1caa2 | 2010-07-29 16:01:11 +0000 | [diff] [blame] | 365 | app.add_directive_to_domain('py', 'decorator', PyDecoratorFunction) |
| 366 | app.add_directive_to_domain('py', 'decoratormethod', PyDecoratorMethod) |
Georg Brandl | 2cac28b | 2012-09-30 15:10:06 +0200 | [diff] [blame] | 367 | app.add_directive('miscnews', MiscNews) |