diff --git a/sphinx/builders/__init__.py b/sphinx/builders/__init__.py index 2a28fd1c4..996a8c6a5 100644 --- a/sphinx/builders/__init__.py +++ b/sphinx/builders/__init__.py @@ -19,7 +19,6 @@ except ImportError: multiprocessing = threading = None from docutils import nodes -from six import string_types from sphinx.util import i18n, path_stabilize from sphinx.util.osutil import SEP, relative_uri, find_catalog diff --git a/sphinx/builders/devhelp.py b/sphinx/builders/devhelp.py index 8e334b3f6..e6199e621 100644 --- a/sphinx/builders/devhelp.py +++ b/sphinx/builders/devhelp.py @@ -33,6 +33,7 @@ except ImportError: try: import gzip + def comp_open(filename, mode='rb'): return gzip.open(filename + '.gz', mode) except ImportError: @@ -81,7 +82,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): def write_toc(node, parent): if isinstance(node, addnodes.compact_paragraph) or \ - isinstance(node, nodes.bullet_list): + isinstance(node, nodes.bullet_list): for subnode in node: write_toc(subnode, parent) elif isinstance(node, nodes.list_item): @@ -94,7 +95,7 @@ class DevhelpBuilder(StandaloneHTMLBuilder): def istoctree(node): return isinstance(node, addnodes.compact_paragraph) and \ - 'toctree' in node + 'toctree' in node for node in tocdoc.traverse(istoctree): write_toc(node, chapters) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index 9b0c34c49..cdcfed2b7 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -40,7 +40,7 @@ from sphinx.util.console import brown # output but that may be customized by (re-)setting module attributes, # e.g. from conf.py. -_mimetype_template = 'application/epub+zip' # no EOL! +_mimetype_template = 'application/epub+zip' # no EOL! _container_template = u'''\ @@ -221,10 +221,10 @@ class EpubBuilder(StandaloneHTMLBuilder): if isinstance(doctree, nodes.reference) and 'refuri' in doctree: refuri = doctree['refuri'] if refuri.startswith('http://') or refuri.startswith('https://') \ - or refuri.startswith('irc:') or refuri.startswith('mailto:'): + or refuri.startswith('irc:') or refuri.startswith('mailto:'): return result classes = doctree.parent.attributes['classes'] - for level in range(8, 0, -1): # or range(1, 8)? + for level in range(8, 0, -1): # or range(1, 8)? if (_toctree_template % level) in classes: result.append({ 'level': level, @@ -242,11 +242,12 @@ class EpubBuilder(StandaloneHTMLBuilder): and pre and post files not managed by sphinx. """ doctree = self.env.get_and_resolve_doctree(self.config.master_doc, - self, prune_toctrees=False, includehidden=True) + self, prune_toctrees=False, + includehidden=True) self.refnodes = self.get_refnodes(doctree, []) master_dir = path.dirname(self.config.master_doc) if master_dir: - master_dir += '/' # XXX or os.sep? + master_dir += '/' # XXX or os.sep? for item in self.refnodes: item['refuri'] = master_dir + item['refuri'] self.toc_add_files(self.refnodes) @@ -258,7 +259,7 @@ class EpubBuilder(StandaloneHTMLBuilder): 'level': 1, 'refuri': self.esc(self.config.master_doc + '.html'), 'text': ssp(self.esc( - self.env.titles[self.config.master_doc].astext())) + self.env.titles[self.config.master_doc].astext())) }) for file, text in reversed(self.config.epub_pre_files): refnodes.insert(0, { @@ -392,7 +393,7 @@ class EpubBuilder(StandaloneHTMLBuilder): m = _refuri_re.match(link) if m: subentrylinks[i] = (ismain, - self.fix_fragment(m.group(1), m.group(2))) + self.fix_fragment(m.group(1), m.group(2))) def is_vector_graphics(self, filename): """Does the filename extension indicate a vector graphic format?""" @@ -461,8 +462,7 @@ class EpubBuilder(StandaloneHTMLBuilder): if pagename.startswith('genindex'): self.fix_genindex(addctx['genindexentries']) StandaloneHTMLBuilder.handle_page(self, pagename, addctx, templatename, - outfilename, event_arg) - + outfilename, event_arg) # Finish by building the epub file def handle_finish(self): @@ -529,9 +529,9 @@ class EpubBuilder(StandaloneHTMLBuilder): olen = len(outdir) projectfiles = [] self.files = [] - self.ignored_files = ['.buildinfo', - 'mimetype', 'content.opf', 'toc.ncx', 'META-INF/container.xml', - self.config.epub_basename + '.epub'] + \ + self.ignored_files = ['.buildinfo', 'mimetype', 'content.opf', + 'toc.ncx', 'META-INF/container.xml', + self.config.epub_basename + '.epub'] + \ self.config.epub_exclude_files for root, dirs, files in os.walk(outdir): for fn in files: @@ -579,7 +579,7 @@ class EpubBuilder(StandaloneHTMLBuilder): image, html_tmpl = self.config.epub_cover image = image.replace(os.sep, '/') mpos = content_tmpl.rfind('') - cpos = content_tmpl.rfind('\n', 0 , mpos) + 1 + cpos = content_tmpl.rfind('\n', 0, mpos) + 1 content_tmpl = content_tmpl[:cpos] + \ _cover_template % {'cover': self.esc(self.make_id(image))} + \ content_tmpl[cpos:] @@ -596,7 +596,7 @@ class EpubBuilder(StandaloneHTMLBuilder): }) ctx = {'image': self.esc(image), 'title': self.config.project} self.handle_page( - path.splitext(_coverpage_name)[0], ctx, html_tmpl) + path.splitext(_coverpage_name)[0], ctx, html_tmpl) guide = [] auto_add_cover = True @@ -611,22 +611,22 @@ class EpubBuilder(StandaloneHTMLBuilder): if type == 'toc': auto_add_toc = False guide.append(_guide_template % { - 'type': self.esc(type), - 'title': self.esc(title), - 'uri': self.esc(uri) - }) + 'type': self.esc(type), + 'title': self.esc(title), + 'uri': self.esc(uri) + }) if auto_add_cover and html_tmpl: guide.append(_guide_template % { - 'type': 'cover', - 'title': _guide_titles['cover'], - 'uri': self.esc(_coverpage_name) - }) + 'type': 'cover', + 'title': _guide_titles['cover'], + 'uri': self.esc(_coverpage_name) + }) if auto_add_toc and self.refnodes: guide.append(_guide_template % { - 'type': 'toc', - 'title': _guide_titles['toc'], - 'uri': self.esc(self.refnodes[0]['refuri']) - }) + 'type': 'toc', + 'title': _guide_titles['toc'], + 'uri': self.esc(self.refnodes[0]['refuri']) + }) projectfiles = '\n'.join(projectfiles) spine = '\n'.join(spine) guide = '\n'.join(guide) @@ -635,7 +635,7 @@ class EpubBuilder(StandaloneHTMLBuilder): f = codecs.open(path.join(outdir, outname), 'w', 'utf-8') try: f.write(content_tmpl % - self.content_metadata(projectfiles, spine, guide)) + self.content_metadata(projectfiles, spine, guide)) finally: f.close() @@ -719,7 +719,8 @@ class EpubBuilder(StandaloneHTMLBuilder): if self.config.epub_tocscope == 'default': doctree = self.env.get_and_resolve_doctree(self.config.master_doc, - self, prune_toctrees=False, includehidden=False) + self, prune_toctrees=False, + includehidden=False) refnodes = self.get_refnodes(doctree, []) self.toc_add_files(refnodes) else: @@ -744,9 +745,9 @@ class EpubBuilder(StandaloneHTMLBuilder): projectfiles = ['META-INF/container.xml', 'content.opf', 'toc.ncx'] \ + self.files epub = zipfile.ZipFile(path.join(outdir, outname), 'w', - zipfile.ZIP_DEFLATED) + zipfile.ZIP_DEFLATED) epub.write(path.join(outdir, 'mimetype'), 'mimetype', - zipfile.ZIP_STORED) + zipfile.ZIP_STORED) for file in projectfiles: fp = path.join(outdir, file) epub.write(fp, file, zipfile.ZIP_DEFLATED) diff --git a/sphinx/builders/gettext.py b/sphinx/builders/gettext.py index 63beb4941..c23675d36 100644 --- a/sphinx/builders/gettext.py +++ b/sphinx/builders/gettext.py @@ -130,6 +130,7 @@ timestamp = time() tzdelta = datetime.fromtimestamp(timestamp) - \ datetime.utcfromtimestamp(timestamp) + class LocalTimeZone(tzinfo): def __init__(self, *args, **kw): @@ -213,8 +214,8 @@ class MessageCatalogBuilder(I18nBuilder): if self.config.gettext_location: # generate "#: file1:line1\n#: file2:line2 ..." - pofile.write("#: %s\n" % "\n#: ".join("%s:%s" % - (safe_relpath(source, self.outdir), line) + pofile.write("#: %s\n" % "\n#: ".join( + "%s:%s" % (safe_relpath(source, self.outdir), line) for source, line, _ in positions)) if self.config.gettext_uuid: # generate "# uuid1\n# uuid2\n ..." @@ -223,8 +224,8 @@ class MessageCatalogBuilder(I18nBuilder): # message contains *one* line of text ready for translation message = message.replace('\\', r'\\'). \ - replace('"', r'\"'). \ - replace('\n', '\\n"\n"') + replace('"', r'\"'). \ + replace('\n', '\\n"\n"') pofile.write('msgid "%s"\nmsgstr ""\n\n' % message) finally: diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index e60eb3a0a..3a617bb67 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -78,7 +78,7 @@ class StandaloneHTMLBuilder(Builder): searchindex_filename = 'searchindex.js' add_permalinks = True embedded = False # for things like HTML help or Qt help: suppresses sidebar - search = True # for things like HTML help and Apple help: suppress search + search = True # for things like HTML help and Apple help: suppress search # This is a class attribute because it is mutated by Sphinx.add_javascript. script_files = ['_static/jquery.js', '_static/underscore.js', @@ -194,7 +194,7 @@ class StandaloneHTMLBuilder(Builder): except Exception: pass if old_config_hash != self.config_hash or \ - old_tags_hash != self.tags_hash: + old_tags_hash != self.tags_hash: for docname in self.env.found_docs: yield docname return @@ -230,8 +230,8 @@ class StandaloneHTMLBuilder(Builder): if self._publisher is None: self._publisher = Publisher( - source_class = DocTreeInput, - destination_class=StringOutput) + source_class = DocTreeInput, + destination_class=StringOutput) self._publisher.set_components('standalone', 'restructuredtext', 'pseudoxml') @@ -280,7 +280,7 @@ class StandaloneHTMLBuilder(Builder): continue # deprecated config value if indexname == 'py-modindex' and \ - not self.config.html_use_modindex: + not self.config.html_use_modindex: continue content, collapse = indexcls(domain).generate() if content: @@ -296,10 +296,10 @@ class StandaloneHTMLBuilder(Builder): self.last_updated = None logo = self.config.html_logo and \ - path.basename(self.config.html_logo) or '' + path.basename(self.config.html_logo) or '' favicon = self.config.html_favicon and \ - path.basename(self.config.html_favicon) or '' + path.basename(self.config.html_favicon) or '' if favicon and os.path.splitext(favicon)[1] != '.ico': self.warn('html_favicon is not an .ico file') @@ -394,8 +394,9 @@ class StandaloneHTMLBuilder(Builder): pass related = self.relations.get(related[0]) if parents: - parents.pop() # remove link to the master file; we have a generic - # "back to index" link already + # remove link to the master file; we have a generic + # "back to index" link already + parents.pop() parents.reverse() # title rendered as HTML @@ -505,7 +506,7 @@ class StandaloneHTMLBuilder(Builder): # the entries into two columns genindex = self.env.create_index(self) indexcounts = [] - for _, entries in genindex: + for _k, entries in genindex: indexcounts.append(sum(1 + len(subitems) for _, (_, subitems) in entries)) @@ -821,8 +822,7 @@ class StandaloneHTMLBuilder(Builder): u'# Project: %s\n' u'# Version: %s\n' u'# The remainder of this file is compressed using zlib.\n' - % (self.config.project, self.config.version) - ).encode('utf-8')) + % (self.config.project, self.config.version)).encode('utf-8')) compressor = zlib.compressobj(9) for domainname, domain in iteritems(self.env.domains): for name, dispname, type, docname, anchor, prio in \ @@ -835,8 +835,7 @@ class StandaloneHTMLBuilder(Builder): dispname = u'-' f.write(compressor.compress( (u'%s %s:%s %s %s %s\n' % (name, domainname, type, - prio, uri, dispname) - ).encode('utf-8'))) + prio, uri, dispname)).encode('utf-8'))) f.write(compressor.flush()) finally: f.close() @@ -874,13 +873,13 @@ class DirectoryHTMLBuilder(StandaloneHTMLBuilder): if docname == 'index': return '' if docname.endswith(SEP + 'index'): - return docname[:-5] # up to sep + return docname[:-5] # up to sep return docname + SEP def get_outfilename(self, pagename): if pagename == 'index' or pagename.endswith(SEP + 'index'): - outfilename = path.join(self.outdir, os_path(pagename) - + self.out_suffix) + outfilename = path.join(self.outdir, os_path(pagename) + + self.out_suffix) else: outfilename = path.join(self.outdir, os_path(pagename), 'index' + self.out_suffix) @@ -907,7 +906,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder): if docname in self.env.all_docs: # all references are on the same page... return self.config.master_doc + self.out_suffix + \ - '#document-' + docname + '#document-' + docname else: # chances are this is a html_additional_page return docname + self.out_suffix @@ -1053,7 +1052,7 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder): if docname == 'index': return '' if docname.endswith(SEP + 'index'): - return docname[:-5] # up to sep + return docname[:-5] # up to sep return docname + SEP def dump_context(self, context, filename): diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 8085ee145..9a21fb15b 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -191,7 +191,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def open_file(self, outdir, basename, mode='w'): # open a file with the correct encoding for the selected language return codecs.open(path.join(outdir, basename), mode, - self.encoding, 'xmlcharrefreplace') + self.encoding, 'xmlcharrefreplace') def handle_finish(self): self.build_hhx(self.outdir, self.config.htmlhelp_basename) @@ -220,7 +220,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): staticdir = root.startswith(path.join(outdir, '_static')) for fn in files: if (staticdir and not fn.endswith('.js')) or \ - fn.endswith('.html'): + fn.endswith('.html'): print(path.join(root, fn)[olen:].replace(os.sep, '\\'), file=f) finally: @@ -239,6 +239,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): # the TOC tocdoc = self.env.get_and_resolve_doctree( self.config.master_doc, self, prune_toctrees=False) + def write_toc(node, ullevel=0): if isinstance(node, nodes.list_item): f.write('