summaryrefslogtreecommitdiff
path: root/sphinx/builders/changes.py
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/builders/changes.py')
-rw-r--r--sphinx/builders/changes.py29
1 files changed, 20 insertions, 9 deletions
diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py
index a756742c9..708cefcde 100644
--- a/sphinx/builders/changes.py
+++ b/sphinx/builders/changes.py
@@ -19,10 +19,15 @@ from sphinx.locale import _
from sphinx.theming import Theme
from sphinx.builders import Builder
from sphinx.util.osutil import ensuredir, os_path
-from sphinx.util.console import bold
+from sphinx.util.console import bold # type: ignore
from sphinx.util.fileutil import copy_asset_file
from sphinx.util.pycompat import htmlescape
+if False:
+ # For type annotation
+ from typing import Any, Tuple # NOQA
+ from sphinx.application import Sphinx # NOQA
+
class ChangesBuilder(Builder):
"""
@@ -31,6 +36,7 @@ class ChangesBuilder(Builder):
name = 'changes'
def init(self):
+ # type: () -> None
self.create_template_bridge()
Theme.init_themes(self.confdir, self.config.html_theme_path,
warn=self.warn)
@@ -38,19 +44,21 @@ class ChangesBuilder(Builder):
self.templates.init(self, self.theme)
def get_outdated_docs(self):
+ # type: () -> unicode
return self.outdir
typemap = {
'versionadded': 'added',
'versionchanged': 'changed',
'deprecated': 'deprecated',
- }
+ } # type: Dict[unicode, unicode]
def write(self, *ignored):
+ # type: (Any) -> None
version = self.config.version
- libchanges = {}
- apichanges = []
- otherchanges = {}
+ libchanges = {} # type: Dict[unicode, List[Tuple[unicode, unicode, int]]]
+ apichanges = [] # type: List[Tuple[unicode, unicode, int]]
+ otherchanges = {} # type: Dict[Tuple[unicode, unicode], List[Tuple[unicode, unicode, int]]] # NOQA
if version not in self.env.versionchanges:
self.info(bold('no changes in version %s.' % version))
return
@@ -101,9 +109,9 @@ class ChangesBuilder(Builder):
'show_copyright': self.config.html_show_copyright,
'show_sphinx': self.config.html_show_sphinx,
}
- with codecs.open(path.join(self.outdir, 'index.html'), 'w', 'utf8') as f:
+ with codecs.open(path.join(self.outdir, 'index.html'), 'w', 'utf8') as f: # type: ignore # NOQA
f.write(self.templates.render('changes/frameset.html', ctx))
- with codecs.open(path.join(self.outdir, 'changes.html'), 'w', 'utf8') as f:
+ with codecs.open(path.join(self.outdir, 'changes.html'), 'w', 'utf8') as f: # type: ignore # NOQA
f.write(self.templates.render('changes/versionchanges.html', ctx))
hltext = ['.. versionadded:: %s' % version,
@@ -120,7 +128,7 @@ class ChangesBuilder(Builder):
self.info(bold('copying source files...'))
for docname in self.env.all_docs:
- with codecs.open(self.env.doc2path(docname), 'r',
+ with codecs.open(self.env.doc2path(docname), 'r', # type: ignore
self.env.config.source_encoding) as f:
try:
lines = f.readlines()
@@ -129,7 +137,7 @@ class ChangesBuilder(Builder):
continue
targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html'
ensuredir(path.dirname(targetfn))
- with codecs.open(targetfn, 'w', 'utf-8') as f:
+ with codecs.open(targetfn, 'w', 'utf-8') as f: # type: ignore
text = ''.join(hl(i+1, line) for (i, line) in enumerate(lines))
ctx = {
'filename': self.env.doc2path(docname, None),
@@ -144,6 +152,7 @@ class ChangesBuilder(Builder):
self.outdir)
def hl(self, text, version):
+ # type: (unicode, unicode) -> unicode
text = htmlescape(text)
for directive in ['versionchanged', 'versionadded', 'deprecated']:
text = text.replace('.. %s:: %s' % (directive, version),
@@ -151,10 +160,12 @@ class ChangesBuilder(Builder):
return text
def finish(self):
+ # type: () -> None
pass
def setup(app):
+ # type: (Sphinx) -> None
app.add_builder(ChangesBuilder)
return {