diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-01-12 13:03:53 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2017-01-12 13:03:53 +0900 |
commit | 38d6c34f35c60689f22d1f71ce650ca1e3005ec4 (patch) | |
tree | 0677416d0de03a53ee7d348289d8560e511c2bed | |
parent | ef912eb9a3e923e80d5c6a08fda4597a65d591aa (diff) | |
parent | 478306e052d9711170b1fbe63635edef02853484 (diff) | |
download | sphinx-git-38d6c34f35c60689f22d1f71ce650ca1e3005ec4.tar.gz |
Merge branch 'stable'
50 files changed, 150 insertions, 149 deletions
@@ -88,6 +88,7 @@ Bugs fixed * #3284: Sphinx crashes on parallel build with an extension which raises unserializable exception * #3315: Bibliography crashes on latex build with docclass 'memoir' +* #3328: Could not refer rubric implicitly Release 1.5.1 (released Dec 13, 2016) @@ -25,5 +25,5 @@ universal = 1 [flake8] max-line-length = 95 -ignore = E113,E116,E221,E226,E241,E251,E901 +ignore = E116,E241,E251 exclude = .git,.tox,tests/*,build/*,sphinx/search/*,sphinx/pycode/pgen2/*,doc/ext/example*.py diff --git a/sphinx/__init__.py b/sphinx/__init__.py index ad9493ecd..0c931cd4d 100644 --- a/sphinx/__init__.py +++ b/sphinx/__init__.py @@ -30,7 +30,7 @@ if 'PYTHONWARNINGS' not in os.environ: warnings.filterwarnings('ignore', "'U' mode is deprecated", DeprecationWarning, module='docutils.io') -__version__ = '1.6' +__version__ = '1.6' __released__ = '1.6+' # used when Sphinx builds its own docs # version info for better programmatic use diff --git a/sphinx/apidoc.py b/sphinx/apidoc.py index e48a527a5..0fca17d81 100644 --- a/sphinx/apidoc.py +++ b/sphinx/apidoc.py @@ -384,8 +384,8 @@ Note: By default this script will not overwrite already created files.""") text += ' %s\n' % module d = dict( path = opts.destdir, - sep = False, - dot = '_', + sep = False, + dot = '_', project = opts.header, author = opts.author or 'Author', version = opts.version or '', diff --git a/sphinx/application.py b/sphinx/application.py index c5634b4ca..6ea7b059f 100644 --- a/sphinx/application.py +++ b/sphinx/application.py @@ -632,9 +632,9 @@ class Sphinx(object): else: # ignore invalid keys for compatibility continue - setattr(translator, 'visit_'+node.__name__, visit) + setattr(translator, 'visit_' + node.__name__, visit) if depart: - setattr(translator, 'depart_'+node.__name__, depart) + setattr(translator, 'depart_' + node.__name__, depart) def add_enumerable_node(self, node, figtype, title_getter=None, **kwds): # type: (nodes.Node, unicode, Callable, Any) -> None diff --git a/sphinx/builders/changes.py b/sphinx/builders/changes.py index d6e118d97..fc8532794 100644 --- a/sphinx/builders/changes.py +++ b/sphinx/builders/changes.py @@ -141,7 +141,7 @@ class ChangesBuilder(Builder): targetfn = path.join(self.outdir, 'rst', os_path(docname)) + '.html' ensuredir(path.dirname(targetfn)) with codecs.open(targetfn, 'w', 'utf-8') as f: # type: ignore - text = ''.join(hl(i+1, line) for (i, line) in enumerate(lines)) + text = ''.join(hl(i + 1, line) for (i, line) in enumerate(lines)) ctx = { 'filename': self.env.doc2path(docname, None), 'text': text diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 04d63a046..f7fe53cac 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -522,7 +522,7 @@ class StandaloneHTMLBuilder(Builder): # additional pages from conf.py for pagename, template in self.config.html_additional_pages.items(): - logger.info(' '+pagename, nonl=1) + self.info(' ' + pagename, nonl=1) self.handle_page(pagename, {}, template) # the search page @@ -1003,7 +1003,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder): hashindex = refuri.find('#') if hashindex < 0: continue - hashindex = refuri.find('#', hashindex+1) + hashindex = refuri.find('#', hashindex + 1) if hashindex >= 0: refnode['refuri'] = fname + refuri[hashindex:] @@ -1116,7 +1116,7 @@ class SingleFileHTMLBuilder(StandaloneHTMLBuilder): # additional pages from conf.py for pagename, template in self.config.html_additional_pages.items(): - logger.info(' '+pagename, nonl=1) + self.info(' ' + pagename, nonl=1) self.handle_page(pagename, {}, template) if self.config.html_use_opensearch: diff --git a/sphinx/builders/htmlhelp.py b/sphinx/builders/htmlhelp.py index 852700123..08e6f9df4 100644 --- a/sphinx/builders/htmlhelp.py +++ b/sphinx/builders/htmlhelp.py @@ -215,12 +215,12 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): def build_hhx(self, outdir, outname): logger.info('dumping stopword list...') - with self.open_file(outdir, outname+'.stp') as f: + with self.open_file(outdir, outname + '.stp') as f: for word in sorted(stopwords): print(word, file=f) logger.info('writing project file...') - with self.open_file(outdir, outname+'.hhp') as f: + with self.open_file(outdir, outname + '.hhp') as f: f.write(project_template % { 'outname': outname, 'title': self.config.html_title, @@ -241,7 +241,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): file=f) logger.info('writing TOC file...') - with self.open_file(outdir, outname+'.hhc') as f: + with self.open_file(outdir, outname + '.hhc') as f: f.write(contents_header) # special books f.write('<LI> ' + object_sitemap % (self.config.html_short_title, @@ -266,7 +266,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): if ullevel != 0: f.write('<UL>\n') for subnode in node: - write_toc(subnode, ullevel+1) + write_toc(subnode, ullevel + 1) if ullevel != 0: f.write('</UL>\n') elif isinstance(node, addnodes.compact_paragraph): @@ -282,7 +282,7 @@ class HTMLHelpBuilder(StandaloneHTMLBuilder): logger.info('writing index file...') index = self.env.create_index(self) - with self.open_file(outdir, outname+'.hhk') as f: + with self.open_file(outdir, outname + '.hhk') as f: f.write('<UL>\n') def write_index(title, refs, subitems): diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index d9e5d5696..7b536e9e5 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -243,7 +243,7 @@ class CheckExternalLinksBuilder(Builder): logger.info(darkgray('-local- ') + uri) self.write_entry('local', docname, lineno, uri) elif status == 'working': - logger.info(darkgreen('ok ') + uri + info) + logger.info(darkgreen('ok ') + uri + info) elif status == 'broken': self.write_entry('broken', docname, lineno, uri + ': ' + info) if self.app.quiet or self.app.warningiserror: @@ -261,7 +261,7 @@ class CheckExternalLinksBuilder(Builder): }[code] self.write_entry('redirected ' + text, docname, lineno, uri + ' to ' + info) - logger.info(color('redirect ') + uri + color(' - ' + text + ' to ' + info)) + logger.info(color('redirect ') + uri + color(' - ' + text + ' to ' + info)) def get_target_uri(self, docname, typ=None): # type: (unicode, unicode) -> unicode diff --git a/sphinx/builders/qthelp.py b/sphinx/builders/qthelp.py index 6ed9c6b7e..4223e2ec9 100644 --- a/sphinx/builders/qthelp.py +++ b/sphinx/builders/qthelp.py @@ -98,7 +98,7 @@ project_template = u'''\ ''' section_template = '<section title="%(title)s" ref="%(ref)s"/>' -file_template = ' '*12 + '<file>%(filename)s</file>' +file_template = ' ' * 12 + '<file>%(filename)s</file>' class QtHelpBuilder(StandaloneHTMLBuilder): @@ -203,7 +203,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder): nspace = nspace.lower() # write the project file - with codecs.open(path.join(outdir, outname+'.qhp'), 'w', 'utf-8') as f: # type: ignore + with codecs.open(path.join(outdir, outname + '.qhp'), 'w', 'utf-8') as f: # type: ignore f.write(project_template % { # type: ignore 'outname': htmlescape(outname), 'title': htmlescape(self.config.html_title), @@ -220,7 +220,7 @@ class QtHelpBuilder(StandaloneHTMLBuilder): startpage = 'qthelp://' + posixpath.join(nspace, 'doc', 'index.html') logger.info('writing collection project file...') - with codecs.open(path.join(outdir, outname+'.qhcp'), 'w', 'utf-8') as f: # type: ignore # NOQA + with codecs.open(path.join(outdir, outname + '.qhcp'), 'w', 'utf-8') as f: # type: ignore # NOQA f.write(collection_template % { # type: ignore 'outname': htmlescape(outname), 'title': htmlescape(self.config.html_short_title), @@ -251,10 +251,10 @@ class QtHelpBuilder(StandaloneHTMLBuilder): title = htmlescape(refnode.astext()).replace('"', '"') item = '<section title="%(title)s" ref="%(ref)s">' % \ {'title': title, 'ref': link} - parts.append(' '*4*indentlevel + item) + parts.append(' ' * 4 * indentlevel + item) for subnode in node.children[1]: - parts.extend(self.write_toc(subnode, indentlevel+1)) - parts.append(' '*4*indentlevel + '</section>') + parts.extend(self.write_toc(subnode, indentlevel + 1)) + parts.append(' ' * 4 * indentlevel + '</section>') elif isinstance(node, nodes.list_item): for subnode in node: parts.extend(self.write_toc(subnode, indentlevel)) @@ -288,10 +288,10 @@ class QtHelpBuilder(StandaloneHTMLBuilder): id = None if id: - item = ' '*12 + '<keyword name="%s" id="%s" ref="%s"/>' % ( + item = ' ' * 12 + '<keyword name="%s" id="%s" ref="%s"/>' % ( name, id, ref[1]) else: - item = ' '*12 + '<keyword name="%s" ref="%s"/>' % (name, ref[1]) + item = ' ' * 12 + '<keyword name="%s" ref="%s"/>' % (name, ref[1]) item.encode('ascii', 'xmlcharrefreplace') return item diff --git a/sphinx/builders/texinfo.py b/sphinx/builders/texinfo.py index 804fd9587..b8a3a38d7 100644 --- a/sphinx/builders/texinfo.py +++ b/sphinx/builders/texinfo.py @@ -136,7 +136,7 @@ class TexinfoBuilder(Builder): 'document %s', docname) continue self.document_data.append(entry) # type: ignore - if docname.endswith(SEP+'index'): + if docname.endswith(SEP + 'index'): docname = docname[:-5] self.titles.append((docname, entry[2])) @@ -227,7 +227,7 @@ class TexinfoBuilder(Builder): if self.images: logger.info(bold('copying images...'), nonl=1) for src, dest in iteritems(self.images): - logger.info(' '+src, nonl=1) + logger.info(' ' + src, nonl=1) copyfile(path.join(self.srcdir, src), path.join(self.outdir, dest)) logger.info('') diff --git a/sphinx/builders/websupport.py b/sphinx/builders/websupport.py index 1154b3419..2ed37a697 100644 --- a/sphinx/builders/websupport.py +++ b/sphinx/builders/websupport.py @@ -141,7 +141,7 @@ class WebSupportBuilder(PickleHTMLBuilder): # "show source" link if ctx.get('sourcename'): source_name = path.join(self.staticdir, - '_sources', os_path(ctx['sourcename'])) + '_sources', os_path(ctx['sourcename'])) ensuredir(path.dirname(source_name)) copyfile(self.env.doc2path(pagename), source_name) diff --git a/sphinx/directives/code.py b/sphinx/directives/code.py index 03936f4e8..e7fdd1274 100644 --- a/sphinx/directives/code.py +++ b/sphinx/directives/code.py @@ -116,7 +116,7 @@ class CodeBlock(Directive): if linespec: try: nlines = len(self.content) - hl_lines = [x+1 for x in parselinenos(linespec, nlines)] + hl_lines = [x + 1 for x in parselinenos(linespec, nlines)] except ValueError as err: document = self.state.document return [document.reporter.warning(str(err), line=self.lineno)] @@ -277,7 +277,7 @@ class LiteralInclude(Directive): 'Object named %r not found in include file %r' % (objectname, filename), line=self.lineno)] else: - lines = lines[tags[objectname][1]-1: tags[objectname][2]-1] + lines = lines[tags[objectname][1] - 1: tags[objectname][2] - 1] if 'lineno-match' in self.options: linenostart = tags[objectname][1] @@ -309,7 +309,7 @@ class LiteralInclude(Directive): linespec = self.options.get('emphasize-lines') if linespec: try: - hl_lines = [x+1 for x in parselinenos(linespec, len(lines))] + hl_lines = [x + 1 for x in parselinenos(linespec, len(lines))] except ValueError as err: return [document.reporter.warning(str(err), line=self.lineno)] else: diff --git a/sphinx/directives/other.py b/sphinx/directives/other.py index 06a3f745d..801fd8cad 100644 --- a/sphinx/directives/other.py +++ b/sphinx/directives/other.py @@ -215,7 +215,7 @@ class VersionChange(Directive): text = versionlabels[self.name] % self.arguments[0] if len(self.arguments) == 2: inodes, messages = self.state.inline_text(self.arguments[1], - self.lineno+1) + self.lineno + 1) para = nodes.paragraph(self.arguments[1], '', *inodes, translatable=False) set_source_info(self, para) node.append(para) @@ -340,7 +340,7 @@ class HList(Directive): index = 0 newnode = addnodes.hlist() for column in range(ncolumns): - endindex = index + (column < nmore and (npercol+1) or npercol) + endindex = index + (column < nmore and (npercol + 1) or npercol) col = addnodes.hlistcol() col += nodes.bullet_list() col[0] += fulllist.children[index:endindex] diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index 22b221318..8afff5716 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -85,7 +85,7 @@ class CObject(ObjectDescription): # add cross-ref nodes for all words for part in [_f for _f in wsplit_re.split(ctype) if _f]: # type: ignore tnode = nodes.Text(part, part) - if part[0] in string.ascii_letters+'_' and \ + if part[0] in string.ascii_letters + '_' and \ part not in self.stopwords: pnode = addnodes.pending_xref( '', refdomain='c', reftype='type', reftarget=part, @@ -172,7 +172,7 @@ class CObject(ObjectDescription): ctype, argname = arg.rsplit(' ', 1) self._parse_type(param, ctype) # separate by non-breaking space in the output - param += nodes.emphasis(' '+argname, u'\xa0'+argname) + param += nodes.emphasis(' ' + argname, u'\xa0' + argname) except ValueError: # no argument name given, only the type self._parse_type(param, arg) @@ -245,7 +245,7 @@ class CXRefRole(XRefRole): title = title[1:] dot = title.rfind('.') if dot != -1: - title = title[dot+1:] + title = title[dot + 1:] return title, target diff --git a/sphinx/domains/cpp.py b/sphinx/domains/cpp.py index cfdbc99d9..181ed3f78 100644 --- a/sphinx/domains/cpp.py +++ b/sphinx/domains/cpp.py @@ -3198,14 +3198,14 @@ class Symbol(object): def to_string(self, indent): # type: (int) -> unicode - res = ['\t'*indent] # type: List[unicode] + res = ['\t' * indent] # type: List[unicode] if not self.parent: res.append('::') else: if self.templateParams: res.append(text_type(self.templateParams)) res.append('\n') - res.append('\t'*indent) + res.append('\t' * indent) if self.identifier: res.append(text_type(self.identifier)) else: diff --git a/sphinx/domains/javascript.py b/sphinx/domains/javascript.py index 6d7920411..4cd0eda6e 100644 --- a/sphinx/domains/javascript.py +++ b/sphinx/domains/javascript.py @@ -160,7 +160,7 @@ class JSXRefRole(XRefRole): title = title[1:] dot = title.rfind('.') if dot != -1: - title = title[dot+1:] + title = title[dot + 1:] if target[0:1] == '.': target = target[1:] refnode['refspecific'] = True diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 2efc6db0b..688062be6 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -563,7 +563,7 @@ class PyXRefRole(XRefRole): title = title[1:] dot = title.rfind('.') if dot != -1: - title = title[dot+1:] + title = title[dot + 1:] # if the first character is a dot, search more specific namespaces first # else search builtins first if target[0:1] == '.': diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 9869f71aa..eeca858ca 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -77,7 +77,7 @@ class GenericObject(ObjectDescription): colon = self.indextemplate.find(':') if colon != -1: indextype = self.indextemplate[:colon].strip() - indexentry = self.indextemplate[colon+1:].strip() % (name,) + indexentry = self.indextemplate[colon + 1:].strip() % (name,) else: indextype = 'single' indexentry = self.indextemplate % (name,) @@ -139,7 +139,7 @@ class Target(Directive): colon = indexentry.find(':') if colon != -1: indextype = indexentry[:colon].strip() - indexentry = indexentry[colon+1:].strip() + indexentry = indexentry[colon + 1:].strip() inode = addnodes.index(entries=[(indextype, indexentry, targetname, '', None)]) ret.insert(0, inode) @@ -600,7 +600,7 @@ class StandardDomain(Domain): 'in ' + env.doc2path(labels[name][0]), location=node) anonlabels[name] = docname, labelid - if node.tagname == 'section': + if node.tagname in ('section', 'rubric'): sectname = clean_astext(node[0]) # node[0] == title node elif self.is_enumerable_node(node): sectname = self.get_numfig_title(node) diff --git a/sphinx/environment/__init__.py b/sphinx/environment/__init__.py index dee67c96d..8de0a9960 100644 --- a/sphinx/environment/__init__.py +++ b/sphinx/environment/__init__.py @@ -692,7 +692,7 @@ class BuildEnvironment(object): lineend = len(error.object) lineno = error.object.count(b'\n', 0, error.start) + 1 logger.warning('undecodable source characters, replacing with "?": %r', - (error.object[linestart+1:error.start] + b'>>>' + + (error.object[linestart + 1:error.start] + b'>>>' + error.object[error.start:error.end] + b'<<<' + error.object[error.end:lineend]), location=(self.docname, lineno)) diff --git a/sphinx/environment/managers/toctree.py b/sphinx/environment/managers/toctree.py index 8f247c986..c272e891d 100644 --- a/sphinx/environment/managers/toctree.py +++ b/sphinx/environment/managers/toctree.py @@ -241,11 +241,11 @@ class Toctree(EnvironmentManager): if isinstance(subnode, (addnodes.compact_paragraph, nodes.list_item)): # for <p> and <li>, indicate the depth level and recurse - subnode['classes'].append('toctree-l%d' % (depth-1)) + subnode['classes'].append('toctree-l%d' % (depth - 1)) _toctree_add_classes(subnode, depth) elif isinstance(subnode, nodes.bullet_list): # for <ul>, just recurse - _toctree_add_classes(subnode, depth+1) + _toctree_add_classes(subnode, depth + 1) elif isinstance(subnode, nodes.reference): # for <a>, identify which entries point to the current # document and therefore may not be collapsed @@ -435,7 +435,7 @@ class Toctree(EnvironmentManager): subnode.parent.remove(subnode) else: # recurse on visible children - self._toctree_prune(subnode, depth+1, maxdepth, collapse) + self._toctree_prune(subnode, depth + 1, maxdepth, collapse) def assign_section_numbers(self): # type: () -> List[unicode] @@ -453,7 +453,7 @@ class Toctree(EnvironmentManager): for subnode in node.children: if isinstance(subnode, nodes.bullet_list): numstack.append(0) - _walk_toc(subnode, secnums, depth-1, titlenode) + _walk_toc(subnode, secnums, depth - 1, titlenode) numstack.pop() titlenode = None elif isinstance(subnode, nodes.list_item): diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py index 89fdbe522..4f3ce4c65 100644 --- a/sphinx/ext/autosummary/__init__.py +++ b/sphinx/ext/autosummary/__init__.py @@ -111,7 +111,7 @@ def process_autosummary_toc(app, doctree): if not isinstance(subnode, nodes.section): continue if subnode not in crawled: - crawl_toc(subnode, depth+1) + crawl_toc(subnode, depth + 1) crawl_toc(doctree) @@ -284,7 +284,7 @@ class Autosummary(Directive): if not isinstance(obj, ModuleType): # give explicitly separated module name, so that members # of inner classes can be documented - full_name = modname + '::' + full_name[len(modname)+1:] + full_name = modname + '::' + full_name[len(modname) + 1:] # NB. using full_name here is important, since Documenters # handle module prefixes slightly differently documenter = get_documenter(obj, parent)(self, full_name) @@ -423,13 +423,13 @@ def mangle_signature(sig, max_chars=30): s = m.group(1)[:-2] # Produce a more compact signature - sig = limited_join(", ", args, max_chars=max_chars-2) + sig = limited_join(", ", args, max_chars=max_chars - 2) if opts: if not sig: - sig = "[%s]" % limited_join(", ", opts, max_chars=max_chars-4) + sig = "[%s]" % limited_join(", ", opts, max_chars=max_chars - 4) elif len(sig) < max_chars - 4 - 2 - 3: sig += "[, %s]" % limited_join(", ", opts, - max_chars=max_chars-len(sig)-4-2) + max_chars=max_chars - len(sig) - 4 - 2) return u"(%s)" % sig @@ -521,7 +521,7 @@ def _import_by_name(name): # ... then as MODNAME, MODNAME.OBJ1, MODNAME.OBJ1.OBJ2, ... last_j = 0 modname = None - for j in reversed(range(1, len(name_parts)+1)): + for j in reversed(range(1, len(name_parts) + 1)): last_j = j modname = '.'.join(name_parts[:j]) try: diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index dafe2863e..c355415f7 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -260,7 +260,7 @@ class DocTestBuilder(Builder): self.outfile.write('''\ Results of doctest builder run on %s ==================================%s -''' % (date, '='*len(date))) +''' % (date, '=' * len(date))) def _out(self, text): # type: (unicode) -> None @@ -377,7 +377,7 @@ Doctest summary return self._out('\nDocument: %s\n----------%s\n' % - (docname, '-'*len(docname))) + (docname, '-' * len(docname))) for group in itervalues(groups): self.test_group(group, self.env.doc2path(docname, base=None)) # Separately count results from setup code diff --git a/sphinx/ext/imgmath.py b/sphinx/ext/imgmath.py index e559530c3..168862d28 100644 --- a/sphinx/ext/imgmath.py +++ b/sphinx/ext/imgmath.py @@ -231,7 +231,7 @@ def get_tooltip(self, node): def html_visit_math(self, node): # type: (nodes.NodeVisitor, math_node) -> None try: - fname, depth = render_math(self, '$'+node['latex']+'$') + fname, depth = render_math(self, '$' + node['latex'] + '$') except MathExtError as exc: msg = text_type(exc) sm = nodes.system_message(msg, type='WARNING', level=2, diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index af39722ce..fac640e00 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -83,7 +83,7 @@ def read_inventory_v1(f, uri, join): return invdata -def read_inventory_v2(f, uri, join, bufsize=16*1024): +def read_inventory_v2(f, uri, join, bufsize=16 * 1024): # type: (IO, unicode, Callable, int) -> Inventory invdata = {} # type: Inventory line = f.readline() @@ -109,7 +109,7 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024): lineend = buf.find(b'\n') while lineend != -1: yield buf[:lineend].decode('utf-8') - buf = buf[lineend+1:] + buf = buf[lineend + 1:] lineend = buf.find(b'\n') assert not buf @@ -134,7 +134,7 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024): return invdata -def read_inventory(f, uri, join, bufsize=16*1024): +def read_inventory(f, uri, join, bufsize=16 * 1024): # type: (IO, unicode, Callable, int) -> Inventory line = f.readline().rstrip().decode('utf-8') if line == '# Sphinx inventory version 1': @@ -371,9 +371,9 @@ def missing_reference(app, env, node, contnode): (domain == 'std' and node['reftype'] == 'keyword'): # use whatever title was given, but strip prefix title = contnode.astext() - if in_set and title.startswith(in_set+':'): - newnode.append(contnode.__class__(title[len(in_set)+1:], - title[len(in_set)+1:])) + if in_set and title.startswith(in_set + ':'): + newnode.append(contnode.__class__(title[len(in_set) + 1:], + title[len(in_set) + 1:])) else: newnode.append(contnode) else: diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py index f4431b07f..0bc941ee2 100644 --- a/sphinx/ext/pngmath.py +++ b/sphinx/ext/pngmath.py @@ -203,7 +203,7 @@ def get_tooltip(self, node): def html_visit_math(self, node): # type: (nodes.NodeVisitor, math_node) -> None try: - fname, depth = render_math(self, '$'+node['latex']+'$') + fname, depth = render_math(self, '$' + node['latex'] + '$') except MathExtError as exc: msg = text_type(exc) sm = nodes.system_message(msg, type='WARNING', level=2, diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py index f575e7462..430135721 100644 --- a/sphinx/ext/todo.py +++ b/sphinx/ext/todo.py @@ -152,7 +152,7 @@ def process_todo_nodes(app, doctree, fromdocname): (todo_info['source'], todo_info['lineno']) ) desc1 = description[:description.find('<<')] - desc2 = description[description.find('>>')+2:] + desc2 = description[description.find('>>') + 2:] para += nodes.Text(desc1, desc1) # Create a reference diff --git a/sphinx/make_mode.py b/sphinx/make_mode.py index 2da5d5b71..346f9db2d 100644 --- a/sphinx/make_mode.py +++ b/sphinx/make_mode.py @@ -83,7 +83,7 @@ class Make(object): def build_help(self): # type: () -> None print(bold("Sphinx v%s" % sphinx.__display_version__)) - print("Please use `make %s' where %s is one of" % ((blue('target'),)*2)) # type: ignore # NOQA + print("Please use `make %s' where %s is one of" % ((blue('target'),) * 2)) # type: ignore # NOQA for osname, bname, description in BUILDERS: if not osname or os.name == osname: print(' %s %s' % (blue(bname.ljust(10)), description)) diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py index 2c898560b..bf8848305 100644 --- a/sphinx/pycode/__init__.py +++ b/sphinx/pycode/__init__.py @@ -368,4 +368,4 @@ if __name__ == '__main__': pprint.pprint(ma.find_tags()) x3 = time.time() # print nodes.nice_repr(ma.parsetree, number2name) - print("tokenizing %.4f, parsing %.4f, finding %.4f" % (x1-x0, x2-x1, x3-x2)) + print("tokenizing %.4f, parsing %.4f, finding %.4f" % (x1 - x0, x2 - x1, x3 - x2)) diff --git a/sphinx/pycode/nodes.py b/sphinx/pycode/nodes.py index b6b3355c0..099fc2cf2 100644 --- a/sphinx/pycode/nodes.py +++ b/sphinx/pycode/nodes.py @@ -39,7 +39,7 @@ class BaseNode(object): if child is self: if i == 0: return None - return self.parent.children[i-1] + return self.parent.children[i - 1] def get_next_sibling(self): """Return next child in parent's children, or None.""" @@ -48,7 +48,7 @@ class BaseNode(object): for i, child in enumerate(self.parent.children): if child is self: try: - return self.parent.children[i+1] + return self.parent.children[i + 1] except IndexError: return None diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index eb5349ede..66a3b057a 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -302,11 +302,11 @@ document is a custom template, you can also set this to another filename.''') do_prompt(d, 'master', 'Name of your master document (without suffix)', 'index') - while path.isfile(path.join(d['path'], d['master']+d['suffix'])) or \ - path.isfile(path.join(d['path'], 'source', d['master']+d['suffix'])): + while path.isfile(path.join(d['path'], d['master'] + d['suffix'])) or \ + path.isfile(path.join(d['path'], 'source', d['master'] + d['suffix'])): print() print(bold('Error: the master file %s has already been found in the ' - 'selected root path.' % (d['master']+d['suffix']))) + 'selected root path.' % (d['master'] + d['suffix']))) print('sphinx-quickstart will not overwrite the existing file.') print() do_prompt(d, 'master', 'Please enter a new file name, or rename the ' @@ -633,7 +633,7 @@ def main(argv=sys.argv): d.setdefault('version', '') d.setdefault('release', d['version']) d2 = DEFAULT_VALUE.copy() - d2.update(dict(("ext_"+ext, False) for ext in EXTENSIONS)) + d2.update(dict(("ext_" + ext, False) for ext in EXTENSIONS)) d2.update(d) d = d2 if 'no_makefile' in d: diff --git a/sphinx/roles.py b/sphinx/roles.py index 182a3db21..6723b0122 100644 --- a/sphinx/roles.py +++ b/sphinx/roles.py @@ -201,7 +201,7 @@ def indexmarkup_role(typ, rawtext, text, lineno, inliner, return [prb], [msg] ref = inliner.document.settings.pep_base_url + 'pep-%04d' % pepnum sn = nodes.strong(title, title) - rn = nodes.reference('', '', internal=False, refuri=ref+anchor, + rn = nodes.reference('', '', internal=False, refuri=ref + anchor, classes=[typ]) rn += sn return [indexnode, targetnode, rn], [] @@ -223,7 +223,7 @@ def indexmarkup_role(typ, rawtext, text, lineno, inliner, return [prb], [msg] ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum sn = nodes.strong(title, title) - rn = nodes.reference('', '', internal=False, refuri=ref+anchor, + rn = nodes.reference('', '', internal=False, refuri=ref + anchor, classes=[typ]) rn += sn return [indexnode, targetnode, rn], [] diff --git a/sphinx/transforms/i18n.py b/sphinx/transforms/i18n.py index 8663c573d..04bc4f8ee 100644 --- a/sphinx/transforms/i18n.py +++ b/sphinx/transforms/i18n.py @@ -123,7 +123,7 @@ class Locale(Transform): # literalblock need literal block notation to avoid it become # paragraph. if isinstance(node, LITERAL_TYPE_NODES): - msgstr = '::\n\n' + indent(msgstr, ' '*3) + msgstr = '::\n\n' + indent(msgstr, ' ' * 3) patch = publish_msgstr( env.app, msgstr, source, node.line, env.config, settings) @@ -249,7 +249,7 @@ class Locale(Transform): # literalblock need literal block notation to avoid it become # paragraph. if isinstance(node, LITERAL_TYPE_NODES): - msgstr = '::\n\n' + indent(msgstr, ' '*3) + msgstr = '::\n\n' + indent(msgstr, ' ' * 3) patch = publish_msgstr( env.app, msgstr, source, node.line, env.config, settings) diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index ff5e35fa4..f2cb2f24b 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -110,7 +110,7 @@ def get_matching_docs(dirname, suffixes, exclude_matchers=()): for filename in get_matching_files(dirname, exclude_matchers): for suffixpattern in suffixpatterns: if fnmatch.fnmatch(filename, suffixpattern): # type: ignore - yield filename[:-len(suffixpattern)+1] + yield filename[:-len(suffixpattern) + 1] break @@ -183,7 +183,7 @@ def copy_static_entry(source, targetdir, builder, context={}, if path.isdir(path.join(source, entry)): newtarget = path.join(targetdir, entry) copy_static_entry(path.join(source, entry), newtarget, - builder, context, level=level+1, + builder, context, level=level + 1, exclude_matchers=exclude_matchers) @@ -380,9 +380,9 @@ def parselinenos(spec, total): if len(begend) > 2: raise ValueError if len(begend) == 1: - items.append(int(begend[0])-1) + items.append(int(begend[0]) - 1) else: - start = (begend[0] == '') and 0 or int(begend[0])-1 + start = (begend[0] == '') and 0 or int(begend[0]) - 1 end = (begend[1] == '') and total or int(begend[1]) items.extend(range(start, end)) except Exception: @@ -420,13 +420,13 @@ def rpartition(s, t): """Similar to str.rpartition from 2.5, but doesn't return the separator.""" i = s.rfind(t) if i != -1: - return s[:i], s[i+len(t):] + return s[:i], s[i + len(t):] return '', s def split_into(n, type, value): """Split an index entry into a given number of parts at semicolons.""" - parts = [x.strip() for x in value.split(';', n-1)] + parts = [x.strip() for x in value.split(';', n - 1)] if sum(1 for part in parts if part) < n: raise ValueError('invalid %s index entry %r' % (type, value)) return parts diff --git a/sphinx/util/console.py b/sphinx/util/console.py index f4e03775f..b418edfb8 100644 --- a/sphinx/util/console.py +++ b/sphinx/util/console.py @@ -123,8 +123,8 @@ _colors = [ ] for i, (dark, light) in enumerate(_colors): - codes[dark] = '\x1b[%im' % (i+30) - codes[light] = '\x1b[%i;01m' % (i+30) + codes[dark] = '\x1b[%im' % (i + 30) + codes[light] = '\x1b[%i;01m' % (i + 30) _orig_codes = codes.copy() diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index ad80ac7a7..ae106c190 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -31,7 +31,7 @@ if False: from sphinx.environment import BuildEnvironment # NOQA -__version_info__ = tuple(map(int, docutils.__version__.split('.'))) +__version_info__ = tuple(map(int, docutils.__version__.split('.'))) @contextmanager diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py index 330b5c0ee..7c60a1b70 100644 --- a/sphinx/util/jsdump.py +++ b/sphinx/util/jsdump.py @@ -20,8 +20,8 @@ if False: # For type annotation from typing import Any, IO, Union # NOQA -_str_re = re.compile(r'"(\\\\|\\"|[^"])*"') -_int_re = re.compile(r'\d+') +_str_re = re.compile(r'"(\\\\|\\"|[^"])*"') +_int_re = re.compile(r'\d+') _name_re = re.compile(r'[a-zA-Z_]\w*') _nameonly_re = re.compile(r'[a-zA-Z_][a-zA-Z0-9_]*$') diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py index 4c574c242..e50de9630 100644 --- a/sphinx/util/nodes.py +++ b/sphinx/util/nodes.py @@ -266,15 +266,15 @@ def process_index_entry(entry, targetid): main = 'main' entry = entry[1:].lstrip() for type in pairindextypes: - if entry.startswith(type+':'): - value = entry[len(type)+1:].strip() + if entry.startswith(type + ':'): + value = entry[len(type) + 1:].strip() value = pairindextypes[type] + '; ' + value indexentries.append(('pair', value, targetid, main, None)) break else: for type in indextypes: - if entry.startswith(type+':'): - value = entry[len(type)+1:].strip() + if entry.startswith(type + ':'): + value = entry[len(type) + 1:].strip() if type == 'double': type = 'pair' indexentries.append((type, value, targetid, main, None)) diff --git a/sphinx/util/osutil.py b/sphinx/util/osutil.py index 5561f0ddb..ba2e1abf4 100644 --- a/sphinx/util/osutil.py +++ b/sphinx/util/osutil.py @@ -30,7 +30,7 @@ if False: # Errnos that we need. EEXIST = getattr(errno, 'EEXIST', 0) ENOENT = getattr(errno, 'ENOENT', 0) -EPIPE = getattr(errno, 'EPIPE', 0) +EPIPE = getattr(errno, 'EPIPE', 0) EINVAL = getattr(errno, 'EINVAL', 0) # SEP separates path elements in the canonical file names @@ -73,7 +73,7 @@ def relative_uri(base, to): # Special case: relative_uri('f/index.html','f/') should # return './', not '' return '.' + SEP - return ('..' + SEP) * (len(b2)-1) + SEP.join(t2) + return ('..' + SEP) * (len(b2) - 1) + SEP.join(t2) def ensuredir(path): diff --git a/sphinx/util/parallel.py b/sphinx/util/parallel.py index 1d97a511c..fc691bee1 100644 --- a/sphinx/util/parallel.py +++ b/sphinx/util/parallel.py @@ -140,11 +140,11 @@ def make_chunks(arguments, nproc, maxbatch=10): chunksize = nargs // nproc if chunksize >= maxbatch: # try to improve batch size vs. number of batches - chunksize = int(sqrt(nargs/nproc * maxbatch)) + chunksize = int(sqrt(nargs / nproc * maxbatch)) if chunksize == 0: chunksize = 1 nchunks, rest = divmod(nargs, chunksize) if rest: nchunks += 1 # partition documents in "chunks" that will be written by one Process - return [arguments[i*chunksize:(i+1)*chunksize] for i in range(nchunks)] + return [arguments[i * chunksize:(i + 1) * chunksize] for i in range(nchunks)] diff --git a/sphinx/util/stemmer/porter.py b/sphinx/util/stemmer/porter.py index 7cff74b6c..5f8d14ed6 100644 --- a/sphinx/util/stemmer/porter.py +++ b/sphinx/util/stemmer/porter.py @@ -107,7 +107,7 @@ class PorterStemmer(object): """doublec(j) is TRUE <=> j,(j-1) contain a double consonant.""" if j < (self.k0 + 1): return 0 - if (self.b[j] != self.b[j-1]): + if (self.b[j] != self.b[j - 1]): return 0 return self.cons(j) @@ -120,8 +120,8 @@ class PorterStemmer(object): cav(e), lov(e), hop(e), crim(e), but snow, box, tray. """ - if i < (self.k0 + 2) or not self.cons(i) or self.cons(i-1) \ - or not self.cons(i-2): + if i < (self.k0 + 2) or not self.cons(i) or self.cons(i - 1) \ + or not self.cons(i - 2): return 0 ch = self.b[i] if ch == 'w' or ch == 'x' or ch == 'y': @@ -135,7 +135,7 @@ class PorterStemmer(object): return 0 if length > (self.k - self.k0 + 1): return 0 - if self.b[self.k-length+1:self.k+1] != s: + if self.b[self.k - length + 1:self.k + 1] != s: return 0 self.j = self.k - length return 1 @@ -144,7 +144,7 @@ class PorterStemmer(object): """setto(s) sets (j+1),...k to the characters in the string s, readjusting k.""" length = len(s) - self.b = self.b[:self.j+1] + s + self.b[self.j+length+1:] + self.b = self.b[:self.j + 1] + s + self.b[self.j + length + 1:] self.k = self.j + length def r(self, s): @@ -203,7 +203,7 @@ class PorterStemmer(object): """step1c() turns terminal y to i when there is another vowel in the stem.""" if (self.ends("y") and self.vowelinstem()): - self.b = self.b[:self.k] + 'i' + self.b[self.k+1:] + self.b = self.b[:self.k] + 'i' + self.b[self.k + 1:] def step2(self): """step2() maps double suffices to single ones. @@ -376,7 +376,7 @@ class PorterStemmer(object): self.j = self.k if self.b[self.k] == 'e': a = self.m() - if a > 1 or (a == 1 and not self.cvc(self.k-1)): + if a > 1 or (a == 1 and not self.cvc(self.k - 1)): self.k = self.k - 1 if self.b[self.k] == 'l' and self.doublec(self.k) and self.m() > 1: self.k = self.k - 1 @@ -408,4 +408,4 @@ class PorterStemmer(object): self.step3() self.step4() self.step5() - return self.b[self.k0:self.k+1] + return self.b[self.k0:self.k + 1] diff --git a/sphinx/websupport/search/__init__.py b/sphinx/websupport/search/__init__.py index 80b5a3535..48279f0a8 100644 --- a/sphinx/websupport/search/__init__.py +++ b/sphinx/websupport/search/__init__.py @@ -106,7 +106,7 @@ class BaseSearch(object): res = self.context_re.search(text) if res is None: return '' - context_start = max(res.start() - int(length/2), 0) + context_start = max(res.start() - int(length / 2), 0) context_end = context_start + length context = ''.join([context_start > 0 and '...' or '', text[context_start:context_end], diff --git a/sphinx/writers/html.py b/sphinx/writers/html.py index 4cc669a36..4ad77de6d 100644 --- a/sphinx/writers/html.py +++ b/sphinx/writers/html.py @@ -454,7 +454,7 @@ class HTMLTranslator(BaseTranslator): self.body.append(self.starttag(production, 'strong', '')) self.body.append(lastname + '</strong> ::= ') elif lastname is not None: - self.body.append('%s ' % (' '*len(lastname))) + self.body.append('%s ' % (' ' * len(lastname))) production.walkabout(self) self.body.append('\n') self.body.append('</pre>\n') @@ -614,7 +614,7 @@ class HTMLTranslator(BaseTranslator): self.body.append(token) else: # protect runs of multiple spaces; the last one can wrap - self.body.append(' ' * (len(token)-1) + ' ') + self.body.append(' ' * (len(token) - 1) + ' ') else: if self.in_mailto and self.settings.cloak_email_addresses: encoded = self.cloak_email(encoded) diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 221d2b2ac..64b975741 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -1793,7 +1793,7 @@ class LaTeXTranslator(nodes.NodeVisitor): parindex = node.parent.index(node) try: try: - next = node.parent[parindex+1] + next = node.parent[parindex + 1] except IndexError: # last node in parent, look at next after parent # (for section of equal level) if it exists @@ -1856,14 +1856,14 @@ class LaTeXTranslator(nodes.NodeVisitor): elif type == 'pair': p1, p2 = [self.encode(x) for x in split_into(2, 'pair', string)] self.body.append(r'\index{%s!%s%s}\index{%s!%s%s}' % - (p1, p2, m, p2, p1, m)) + (p1, p2, m, p2, p1, m)) elif type == 'triple': p1, p2, p3 = [self.encode(x) for x in split_into(3, 'triple', string)] self.body.append( r'\index{%s!%s %s%s}\index{%s!%s, %s%s}' r'\index{%s!%s %s%s}' % - (p1, p2, p3, m, p2, p3, p1, m, p3, p1, p2, m)) + (p1, p2, p3, m, p2, p3, p1, m, p3, p1, p2, m)) elif type == 'see': p1, p2 = [self.encode(x) for x in split_into(2, 'see', string)] self.body.append(r'\index{%s|see{%s}}' % (p1, p2)) diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 76b402462..e3ce3ed7a 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -263,7 +263,7 @@ class ManualPageTranslator(BaseTranslator): self.body.append(self.defs['strong'][1]) self.body.append(' ::= ') elif lastname is not None: - self.body.append('%s ' % (' '*len(lastname))) + self.body.append('%s ' % (' ' * len(lastname))) production.walkabout(self) self.body.append('\n') self.body.append('\n.fi\n') diff --git a/sphinx/writers/texinfo.py b/sphinx/writers/texinfo.py index a992869e3..07a0e1e83 100644 --- a/sphinx/writers/texinfo.py +++ b/sphinx/writers/texinfo.py @@ -345,10 +345,10 @@ class TexinfoTranslator(nodes.NodeVisitor): for i, id in enumerate(entries): # First child's prev is empty if i != 0: - rellinks[id][1] = entries[i-1] + rellinks[id][1] = entries[i - 1] # Last child's next is empty if i != len(entries) - 1: - rellinks[id][0] = entries[i+1] + rellinks[id][0] = entries[i + 1] # top's next is its first child try: first = node_menus['Top'][0] @@ -416,7 +416,7 @@ class TexinfoTranslator(nodes.NodeVisitor): s = '* %s: %s. ' % (name, node_name) offset = max((24, (len(name) + 4) % 78)) wdesc = '\n'.join(' ' * offset + l for l in - textwrap.wrap(desc, width=78-offset)) + textwrap.wrap(desc, width=78 - offset)) return s + wdesc.strip() + '\n' def add_menu_entries(self, entries, reg=re.compile(r'\s+---?\s+')): @@ -698,7 +698,7 @@ class TexinfoTranslator(nodes.NodeVisitor): parindex = node.parent.index(node) try: try: - next = node.parent[parindex+1] + next = node.parent[parindex + 1] except IndexError: # last node in parent, look at next after parent # (for section of equal level) @@ -1110,7 +1110,7 @@ class TexinfoTranslator(nodes.NodeVisitor): return self.body.append('\n\n@multitable ') for i, n in enumerate(self.colwidths): - self.body.append('{%s} ' % ('x' * (n+2))) + self.body.append('{%s} ' % ('x' * (n + 2))) def depart_colspec(self, node): # type: (nodes.Node) -> None @@ -1450,7 +1450,7 @@ class TexinfoTranslator(nodes.NodeVisitor): self.add_anchor(id, production) s = production['tokenname'].ljust(maxlen) + ' ::=' else: - s = '%s ' % (' '*maxlen) + s = '%s ' % (' ' * maxlen) self.body.append(self.escape(s)) self.body.append(self.escape(production.astext() + '\n')) self.depart_literal_block(None) diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index 9bd427468..46de7a582 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -98,7 +98,7 @@ class TextWrapper(textwrap.TextWrapper): for i, c in enumerate(word): total += column_width(c) if total > space_left: - return word[:i-1], word[i-1:] + return word[:i - 1], word[i - 1:] return word, '' def _split(self, text): @@ -213,7 +213,7 @@ class TextTranslator(nodes.NodeVisitor): if not toformat: return if wrap: - res = my_wrap(''.join(toformat), width=MAXWIDTH-maxindent) + res = my_wrap(''.join(toformat), width=MAXWIDTH - maxindent) else: res = ''.join(toformat).splitlines() if end: @@ -246,7 +246,7 @@ class TextTranslator(nodes.NodeVisitor): def depart_document(self, node): # type: (nodes.Node) -> None self.end_state() - self.body = self.nl.join(line and (' '*indent + line) + self.body = self.nl.join(line and (' ' * indent + line) for indent, lines in self.states[0] for line in lines) # XXX header/footer? @@ -304,7 +304,7 @@ class TextTranslator(nodes.NodeVisitor): def visit_title(self, node): # type: (nodes.Node) -> None if isinstance(node.parent, nodes.Admonition): - self.add_text(node.astext()+': ') + self.add_text(node.astext() + ': ') raise nodes.SkipNode self.new_state(0) @@ -468,7 +468,7 @@ class TextTranslator(nodes.NodeVisitor): self.add_text(production['tokenname'].ljust(maxlen) + ' ::=') lastname = production['tokenname'] elif lastname is not None: - self.add_text('%s ' % (' '*len(lastname))) + self.add_text('%s ' % (' ' * len(lastname))) self.add_text(production.astext() + self.nl) self.end_state(wrap=False) raise nodes.SkipNode @@ -657,7 +657,7 @@ class TextTranslator(nodes.NodeVisitor): # type: (unicode) -> None out = ['+'] # type: List[unicode] for width in realwidths: - out.append(char * (width+2)) + out.append(char * (width + 2)) out.append('+') self.add_text(''.join(out) + self.nl) diff --git a/utils/check_sources.py b/utils/check_sources.py index d4a5ab491..3858cc0b4 100755 --- a/utils/check_sources.py +++ b/utils/check_sources.py @@ -34,7 +34,7 @@ def checker(*suffixes, **kwds): # this one is a byte regex since it is applied before decoding -coding_re = re.compile(br'coding[:=]\s*([-\w.]+)') +coding_re = re.compile(br'coding[:=]\s*([-\w.]+)') uni_coding_re = re.compile(r'^#.*coding[:=]\s*([-\w.]+).*') name_mail_re = r'[\w ]+(<.*?>)?' @@ -44,9 +44,9 @@ copyright_re = re.compile(r'^ :copyright: Copyright 200\d(-20\d\d)? ' license_re = re.compile(r" :license: (.*?).\n") copyright_2_re = re.compile(r'^ %s(, %s)*[,.]$' % (name_mail_re, name_mail_re)) -not_ix_re = re.compile(r'\bnot\s+\S+?\s+i[sn]\s\S+') -is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b') -noqa_re = re.compile(r'#\s+NOQA\s*$', re.I) +not_ix_re = re.compile(r'\bnot\s+\S+?\s+i[sn]\s\S+') +is_const_re = re.compile(r'if.*?==\s+(None|False|True)\b') +noqa_re = re.compile(r'#\s+NOQA\s*$', re.I) misspellings = ["developement", "adress", # ALLOW-MISSPELLING "verificate", "informations"] # ALLOW-MISSPELLING @@ -64,7 +64,7 @@ def decode_source(fn, lines): decoded_lines.append(line.decode(encoding)) except UnicodeDecodeError as err: raise UnicodeError("%s:%d: not decodable: %s\n Line: %r" % - (fn, lno+1, err, line)) + (fn, lno + 1, err, line)) except LookupError as err: raise LookupError("unknown encoding: %s" % encoding) return decoded_lines @@ -85,14 +85,14 @@ def check_style(fn, lines): if noqa_re.search(line): continue if len(line.rstrip('\n')) > 95: - yield lno+1, "line too long" + yield lno + 1, "line too long" if line.strip().startswith('#'): continue # m = not_ix_re.search(line) # if m: # yield lno+1, '"' + m.group() + '"' if is_const_re.search(line): - yield lno+1, 'using == None/True/False' + yield lno + 1, 'using == None/True/False' @checker('.py', only_pkg=True) @@ -119,11 +119,11 @@ def check_fileheader(fn, lines): if l == '"""\n': # end of docstring if lno <= 4: - yield lno+c, "missing module name in docstring" + yield lno + c, "missing module name in docstring" break if l != '\n' and l[:4] != ' ' and docopen: - yield lno+c, "missing correct docstring indentation" + yield lno + c, "missing correct docstring indentation" if lno == 2: # if not in package, don't check the module name @@ -148,10 +148,10 @@ def check_fileheader(fn, lines): yield 0, "no correct license info" ci = -3 - copyright = llist[ci:ci+1] + copyright = llist[ci:ci + 1] while copyright and copyright_2_re.match(copyright[0]): ci -= 1 - copyright = llist[ci:ci+1] + copyright = llist[ci:ci + 1] if not copyright or not copyright_re.match(copyright[0]): yield 0, "no correct copyright info" @@ -160,12 +160,12 @@ def check_fileheader(fn, lines): def check_whitespace_and_spelling(fn, lines): for lno, line in enumerate(lines): if '\t' in line: - yield lno+1, "OMG TABS!!!1 " + yield lno + 1, "OMG TABS!!!1 " if line[:-1].rstrip(' \t') != line[:-1]: - yield lno+1, "trailing whitespace" + yield lno + 1, "trailing whitespace" for word in misspellings: if word in line and 'ALLOW-MISSPELLING' not in line: - yield lno+1, '"%s" used' % word + yield lno + 1, '"%s" used' % word bad_tags = ['<u>', '<s>', '<strike>', '<center>', '<font'] @@ -176,7 +176,7 @@ def check_xhtml(fn, lines): for lno, line in enumerate(lines): for bad_tag in bad_tags: if bad_tag in line: - yield lno+1, "used " + bad_tag + yield lno + 1, "used " + bad_tag def main(argv): diff --git a/utils/jssplitter_generator.py b/utils/jssplitter_generator.py index e236f00d0..078dd7591 100644 --- a/utils/jssplitter_generator.py +++ b/utils/jssplitter_generator.py @@ -35,8 +35,8 @@ def fold(jsonData, splitter): lines.append(' ' + code) break index = code.index(splitter, 70) - lines.append(' ' + code[:index+len(splitter)]) - code = code[index+len(splitter):] + lines.append(' ' + code[:index + len(splitter)]) + code = code[index + len(splitter):] lines[0] = lines[0][8:] return '\n'.join(lines) diff --git a/utils/reindent.py b/utils/reindent.py index a4fe93e24..b79657636 100755 --- a/utils/reindent.py +++ b/utils/reindent.py @@ -55,9 +55,9 @@ if sys.version_info >= (3, 0): else: tokens = tokenize.tokenize -verbose = 0 -recurse = 0 -dryrun = 0 +verbose = 0 +recurse = 0 +dryrun = 0 makebackup = True @@ -160,7 +160,7 @@ def _rstrip(line, JUNK='\n \t'): """ i = len(line) - while i > 0 and line[i-1] in JUNK: + while i > 0 and line[i - 1] in JUNK: i -= 1 return line[:i] @@ -204,9 +204,9 @@ class Reindenter: # we see a line with *something* on it. i = stats[0][0] after.extend(lines[1:i]) - for i in range(len(stats)-1): + for i in range(len(stats) - 1): thisstmt, thislevel = stats[i] - nextstmt = stats[i+1][0] + nextstmt = stats[i + 1][0] have = getlspace(lines[thisstmt]) want = thislevel * 4 if want < 0: @@ -218,7 +218,7 @@ class Reindenter: want = have2want.get(have, -1) if want < 0: # Then it probably belongs to the next real stmt. - for j in range(i+1, len(stats)-1): + for j in range(i + 1, len(stats) - 1): jline, jlevel = stats[j] if jlevel >= 0: if have == getlspace(lines[jline]): @@ -228,10 +228,10 @@ class Reindenter: # comment like this one, # in which case we should shift it like its base # line got shifted. - for j in range(i-1, -1, -1): + for j in range(i - 1, -1, -1): jline, jlevel = stats[j] if jlevel >= 0: - want = (have + getlspace(after[jline-1]) - + want = (have + getlspace(after[jline - 1]) - getlspace(lines[jline])) break if want < 0: |