summaryrefslogtreecommitdiffstats
path: root/Doc/tools/sphinxext/pyspecific.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/tools/sphinxext/pyspecific.py')
-rw-r--r--Doc/tools/sphinxext/pyspecific.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/Doc/tools/sphinxext/pyspecific.py b/Doc/tools/sphinxext/pyspecific.py
index 9c5d401..d1b492a 100644
--- a/Doc/tools/sphinxext/pyspecific.py
+++ b/Doc/tools/sphinxext/pyspecific.py
@@ -10,14 +10,16 @@
"""
ISSUE_URI = 'http://bugs.python.org/issue%s'
-SOURCE_URI = 'https://hg.python.org/cpython/file/3.4/%s'
+SOURCE_URI = 'https://hg.python.org/cpython/file/default/%s'
from docutils import nodes, utils
+import sphinx
from sphinx.util.nodes import split_explicit_title
from sphinx.util.compat import Directive
from sphinx.writers.html import HTMLTranslator
from sphinx.writers.latex import LaTeXTranslator
+from sphinx.locale import versionlabels
# monkey-patch reST parser to disable alphabetic and roman enumerated lists
from docutils.parsers.rst.states import Body
@@ -26,6 +28,20 @@ Body.enum.converters['loweralpha'] = \
Body.enum.converters['lowerroman'] = \
Body.enum.converters['upperroman'] = lambda x: None
+SPHINX11 = sphinx.__version__[:3] < '1.2'
+
+if SPHINX11:
+ # monkey-patch HTML translator to give versionmodified paragraphs a class
+ def new_visit_versionmodified(self, node):
+ self.body.append(self.starttag(node, 'p', CLASS=node['type']))
+ text = versionlabels[node['type']] % node['version']
+ if len(node):
+ text += ':'
+ else:
+ text += '.'
+ self.body.append('<span class="versionmodified">%s</span> ' % text)
+ HTMLTranslator.visit_versionmodified = new_visit_versionmodified
+
# monkey-patch HTML and LaTeX translators to keep doctest blocks in the
# doctest docs themselves
orig_visit_literal_block = HTMLTranslator.visit_literal_block
@@ -158,9 +174,10 @@ class DeprecatedRemoved(Directive):
content.line = node[0].line
content += node[0].children
node[0].replace_self(nodes.paragraph('', '', content))
+ if not SPHINX11:
node[0].insert(0, nodes.inline('', '%s: ' % text,
classes=['versionmodified']))
- else:
+ elif not SPHINX11:
para = nodes.paragraph('', '',
nodes.inline('', '%s.' % text, classes=['versionmodified']))
if len(node):
@@ -171,6 +188,9 @@ class DeprecatedRemoved(Directive):
env.note_versionchange('deprecated', version[0], node, self.lineno)
return [node] + messages
+# for Sphinx < 1.2
+versionlabels['deprecated-removed'] = DeprecatedRemoved._label
+
# Support for including Misc/NEWS
@@ -269,14 +289,14 @@ class PydocTopicsBuilder(Builder):
document.append(doctree.ids[labelid])
destination = StringOutput(encoding='utf-8')
writer.write(document, destination)
- self.topics[label] = writer.output
+ self.topics[label] = writer.output.encode('utf-8')
def finish(self):
- f = open(path.join(self.outdir, 'topics.py'), 'wb')
+ f = open(path.join(self.outdir, 'topics.py'), 'w')
try:
- f.write('# -*- coding: utf-8 -*-\n'.encode('utf-8'))
- f.write(('# Autogenerated by Sphinx on %s\n' % asctime()).encode('utf-8'))
- f.write(('topics = ' + pformat(self.topics) + '\n').encode('utf-8'))
+ f.write('# -*- coding: utf-8 -*-\n')
+ f.write('# Autogenerated by Sphinx on %s\n' % asctime())
+ f.write('topics = ' + pformat(self.topics) + '\n')
finally:
f.close()