diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py
index 27cd54f93..39a393fc3 100644
--- a/sphinx/ext/autodoc.py
+++ b/sphinx/ext/autodoc.py
@@ -62,7 +62,9 @@ class DefDict(dict):
return True
__nonzero__ = __bool__ # for python2 compatibility
-identity = lambda x: x
+
+def identity(x):
+ return x
class Options(dict):
@@ -1311,9 +1313,9 @@ class AttributeDocumenter(DocstringStripSignatureMixin, ClassLevelDocumenter):
isinstance(member, cls.method_types) and not \
type(member).__name__ in ("type", "method_descriptor",
"instancemethod")
- return isdatadesc or (not isinstance(parent, ModuleDocumenter)
- and not inspect.isroutine(member)
- and not isinstance(member, class_types))
+ return isdatadesc or (not isinstance(parent, ModuleDocumenter) and
+ not inspect.isroutine(member) and
+ not isinstance(member, class_types))
def document_members(self, all_members=False):
pass
diff --git a/sphinx/ext/autosummary/__init__.py b/sphinx/ext/autosummary/__init__.py
index de7fe5c7a..d9594638e 100644
--- a/sphinx/ext/autosummary/__init__.py
+++ b/sphinx/ext/autosummary/__init__.py
@@ -77,18 +77,20 @@ from sphinx.ext.autodoc import Options
class autosummary_toc(nodes.comment):
pass
+
def process_autosummary_toc(app, doctree):
"""Insert items described in autosummary:: to the TOC tree, but do
not generate the toctree:: list.
"""
env = app.builder.env
crawled = {}
+
def crawl_toc(node, depth=1):
crawled[node] = True
for j, subnode in enumerate(node):
try:
- if (isinstance(subnode, autosummary_toc)
- and isinstance(subnode[0], addnodes.toctree)):
+ if (isinstance(subnode, autosummary_toc) and
+ isinstance(subnode[0], addnodes.toctree)):
env.note_toctree(env.docname, subnode[0])
continue
except IndexError:
@@ -99,10 +101,12 @@ def process_autosummary_toc(app, doctree):
crawl_toc(subnode, depth+1)
crawl_toc(doctree)
+
def autosummary_toc_visit_html(self, node):
"""Hide autosummary toctree list in HTML output."""
raise nodes.SkipNode
+
def autosummary_noop(self, node):
pass
@@ -112,6 +116,7 @@ def autosummary_noop(self, node):
class autosummary_table(nodes.comment):
pass
+
def autosummary_table_visit_html(self, node):
"""Make the first column of the table non-breaking."""
try:
@@ -134,6 +139,7 @@ class FakeDirective:
env = {}
genopt = Options()
+
def get_documenter(obj, parent):
"""Get an autodoc.Documenter class suitable for documenting the given
object.
@@ -143,7 +149,7 @@ def get_documenter(obj, parent):
belongs to.
"""
from sphinx.ext.autodoc import AutoDirective, DataDocumenter, \
- ModuleDocumenter
+ ModuleDocumenter
if inspect.ismodule(obj):
# ModuleDocumenter.can_document_member always returns False
@@ -219,7 +225,7 @@ class Autosummary(Directive):
tocnode = addnodes.toctree()
tocnode['includefiles'] = docnames
- tocnode['entries'] = [(None, docname) for docname in docnames]
+ tocnode['entries'] = [(None, docn) for docn in docnames]
tocnode['maxdepth'] = -1
tocnode['glob'] = None
@@ -276,7 +282,7 @@ class Autosummary(Directive):
# try to also get a source code analyzer for attribute docs
try:
documenter.analyzer = ModuleAnalyzer.for_module(
- documenter.get_real_modname())
+ documenter.get_real_modname())
# parse right now, to get PycodeErrors on parsing (results will
# be cached anyway)
documenter.analyzer.find_attr_docs()
@@ -369,6 +375,7 @@ class Autosummary(Directive):
return [table_spec, table]
+
def mangle_signature(sig, max_chars=30):
"""Reformat a function signature to a more compact form."""
s = re.sub(r"^\((.*)\)$", r"\1", sig).strip()
@@ -404,6 +411,7 @@ def mangle_signature(sig, max_chars=30):
return u"(%s)" % sig
+
def limited_join(sep, items, max_chars=30, overflow_marker="..."):
"""Join a number of strings to one, limiting the length to *max_chars*.
@@ -427,6 +435,7 @@ def limited_join(sep, items, max_chars=30, overflow_marker="..."):
return sep.join(list(items[:n_items]) + [overflow_marker])
+
# -- Importing items -----------------------------------------------------------
def get_import_prefixes_from_env(env):
@@ -449,6 +458,7 @@ def get_import_prefixes_from_env(env):
return prefixes
+
def import_by_name(name, prefixes=[None]):
"""Import a Python object that has the given *name*, under one of the
*prefixes*. The first name that succeeds is used.
@@ -466,6 +476,7 @@ def import_by_name(name, prefixes=[None]):
tried.append(prefixed_name)
raise ImportError('no module named %s' % ' or '.join(tried))
+
def _import_by_name(name):
"""Import a Python object given its full name."""
try:
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index 6b149a98a..2cacadfd7 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -71,12 +71,15 @@ def main(argv=sys.argv):
"." + options.suffix,
template_dir=options.templates)
+
def _simple_info(msg):
print(msg)
+
def _simple_warn(msg):
print('WARNING: ' + msg, file=sys.stderr)
+
# -- Generating output ---------------------------------------------------------
def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
@@ -169,17 +172,17 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
if doc.objtype == 'module':
ns['members'] = dir(obj)
ns['functions'], ns['all_functions'] = \
- get_members(obj, 'function')
+ get_members(obj, 'function')
ns['classes'], ns['all_classes'] = \
- get_members(obj, 'class')
+ get_members(obj, 'class')
ns['exceptions'], ns['all_exceptions'] = \
- get_members(obj, 'exception')
+ get_members(obj, 'exception')
elif doc.objtype == 'class':
ns['members'] = dir(obj)
ns['methods'], ns['all_methods'] = \
- get_members(obj, 'method', ['__init__'])
+ get_members(obj, 'method', ['__init__'])
ns['attributes'], ns['all_attributes'] = \
- get_members(obj, 'attribute')
+ get_members(obj, 'attribute')
parts = name.split('.')
if doc.objtype in ('method', 'attribute'):
@@ -289,7 +292,7 @@ def find_autosummary_in_lines(lines, module=None, filename=None):
continue
if line.strip().startswith(':'):
- continue # skip options
+ continue # skip options
m = autosummary_item_re.match(line)
if m:
@@ -297,7 +300,7 @@ def find_autosummary_in_lines(lines, module=None, filename=None):
if name.startswith('~'):
name = name[1:]
if current_module and \
- not name.startswith(current_module + '.'):
+ not name.startswith(current_module + '.'):
name = "%s.%s" % (current_module, name)
documented.append((name, toctree, template))
continue
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py
index 5e2cca25e..1e455a6f4 100644
--- a/sphinx/ext/coverage.py
+++ b/sphinx/ext/coverage.py
@@ -27,6 +27,7 @@ def write_header(f, text, char='-'):
f.write(text + '\n')
f.write(char * len(text) + '\n')
+
def compile_regex_list(name, exps, warnfunc):
lst = []
for exp in exps:
@@ -231,7 +232,7 @@ class CoverageBuilder(Builder):
if undoc['classes']:
op.write('Classes:\n')
for name, methods in sorted(
- iteritems(undoc['classes'])):
+ iteritems(undoc['classes'])):
if not methods:
op.write(' * %s\n' % name)
else:
diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py
index 317c34e0b..a05f489c6 100644
--- a/sphinx/ext/doctest.py
+++ b/sphinx/ext/doctest.py
@@ -15,8 +15,6 @@ import sys
import time
import codecs
from os import path
-# circumvent relative import
-doctest = __import__('doctest')
from six import itervalues, StringIO, binary_type
from docutils import nodes
@@ -29,6 +27,9 @@ from sphinx.util.nodes import set_source_info
from sphinx.util.compat import Directive
from sphinx.util.console import bold
+# circumvent relative import
+doctest = __import__('doctest')
+
blankline_re = re.compile(r'^\s*', re.MULTILINE)
doctestopt_re = re.compile(r'#\s*doctest:.+$', re.MULTILINE)
@@ -296,8 +297,8 @@ Doctest summary
if self.config.doctest_test_doctest_blocks:
def condition(node):
- return (isinstance(node, (nodes.literal_block, nodes.comment))
- and 'testnodetype' in node) or \
+ return (isinstance(node, (nodes.literal_block, nodes.comment)) and
+ 'testnodetype' in node) or \
isinstance(node, nodes.doctest_block)
else:
def condition(node):
diff --git a/sphinx/ext/extlinks.py b/sphinx/ext/extlinks.py
index f593dcaae..c9a3f3641 100644
--- a/sphinx/ext/extlinks.py
+++ b/sphinx/ext/extlinks.py
@@ -52,10 +52,12 @@ def make_link_role(base_url, prefix):
return [pnode], []
return role
+
def setup_link_roles(app):
for name, (base_url, prefix) in iteritems(app.config.extlinks):
app.add_role(name, make_link_role(base_url, prefix))
+
def setup(app):
app.add_config_value('extlinks', {}, 'env')
app.connect('builder-inited', setup_link_roles)
diff --git a/sphinx/ext/graphviz.py b/sphinx/ext/graphviz.py
index 320d70b09..56acf7fec 100644
--- a/sphinx/ext/graphviz.py
+++ b/sphinx/ext/graphviz.py
@@ -141,9 +141,8 @@ class GraphvizSimple(Directive):
def render_dot(self, code, options, format, prefix='graphviz'):
"""Render graphviz code into a PNG or PDF output file."""
hashkey = (code + str(options) +
- str(self.builder.config.graphviz_dot) +
- str(self.builder.config.graphviz_dot_args)
- ).encode('utf-8')
+ str(self.builder.config.graphviz_dot) +
+ str(self.builder.config.graphviz_dot_args)).encode('utf-8')
fname = '%s-%s.%s' % (prefix, sha1(hashkey).hexdigest(), format)
relfn = posixpath.join(self.builder.imgpath, fname)
@@ -284,6 +283,7 @@ def render_dot_texinfo(self, node, code, options, prefix='graphviz'):
self.body.append('@image{%s,,,[graphviz],png}\n' % fname[:-4])
raise nodes.SkipNode
+
def texinfo_visit_graphviz(self, node):
render_dot_texinfo(self, node, node['code'], node['options'])
diff --git a/sphinx/ext/ifconfig.py b/sphinx/ext/ifconfig.py
index 47973ecc4..e65943769 100644
--- a/sphinx/ext/ifconfig.py
+++ b/sphinx/ext/ifconfig.py
@@ -27,7 +27,8 @@ from sphinx.util.nodes import set_source_info
from sphinx.util.compat import Directive
-class ifconfig(nodes.Element): pass
+class ifconfig(nodes.Element):
+ pass
class IfConfig(Directive):
diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py
index d35d71c52..60743c496 100644
--- a/sphinx/ext/intersphinx.py
+++ b/sphinx/ext/intersphinx.py
@@ -109,10 +109,10 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024):
continue
name, type, prio, location, dispname = m.groups()
if type == 'py:module' and type in invdata and \
- name in invdata[type]: # due to a bug in 1.1 and below,
- # two inventory entries are created
- # for Python modules, and the first
- # one is correct
+ name in invdata[type]: # due to a bug in 1.1 and below,
+ # two inventory entries are created
+ # for Python modules, and the first
+ # one is correct
continue
if location.endswith(u'$'):
location = location[:-1] + name
@@ -212,7 +212,7 @@ def load_mappings(app):
cached_vals = list(cache.values())
named_vals = sorted(v for v in cached_vals if v[0])
unnamed_vals = [v for v in cached_vals if not v[0]]
- for name, _, invdata in named_vals + unnamed_vals:
+ for name, _x, invdata in named_vals + unnamed_vals:
if name:
env.intersphinx_named_inventory[name] = invdata
for type, objects in iteritems(invdata):
diff --git a/sphinx/ext/jsmath.py b/sphinx/ext/jsmath.py
index 64d1b3a2c..399c9bc09 100644
--- a/sphinx/ext/jsmath.py
+++ b/sphinx/ext/jsmath.py
@@ -22,6 +22,7 @@ def html_visit_math(self, node):
self.body.append(self.encode(node['latex']) + '')
raise nodes.SkipNode
+
def html_visit_displaymath(self, node):
if node['nowrap']:
self.body.append(self.starttag(node, 'div', CLASS='math'))
@@ -46,6 +47,7 @@ def html_visit_displaymath(self, node):
self.body.append('\n')
raise nodes.SkipNode
+
def builder_inited(app):
if not app.config.jsmath_path:
raise ExtensionError('jsmath_path config value must be set for the '
diff --git a/sphinx/ext/mathbase.py b/sphinx/ext/mathbase.py
index 57a7ec314..1c5de3cd7 100644
--- a/sphinx/ext/mathbase.py
+++ b/sphinx/ext/mathbase.py
@@ -19,9 +19,11 @@ from sphinx.util.compat import Directive
class math(nodes.Inline, nodes.TextElement):
pass
+
class displaymath(nodes.Part, nodes.Element):
pass
+
class eqref(nodes.Inline, nodes.TextElement):
pass
@@ -46,6 +48,7 @@ def math_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
latex = utils.unescape(text, restore_backslashes=True)
return [math(latex=latex)], []
+
def eq_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
text = utils.unescape(text)
node = eqref('(?)', '(?)', target=text)
@@ -91,6 +94,7 @@ def latex_visit_math(self, node):
self.body.append('\\(' + node['latex'] + '\\)')
raise nodes.SkipNode
+
def latex_visit_displaymath(self, node):
if node['nowrap']:
self.body.append(node['latex'])
@@ -99,6 +103,7 @@ def latex_visit_displaymath(self, node):
self.body.append(wrap_displaymath(node['latex'], label))
raise nodes.SkipNode
+
def latex_visit_eqref(self, node):
self.body.append('\\eqref{%s-%s}' % (node['docname'], node['target']))
raise nodes.SkipNode
@@ -108,12 +113,14 @@ def text_visit_math(self, node):
self.add_text(node['latex'])
raise nodes.SkipNode
+
def text_visit_displaymath(self, node):
self.new_state()
self.add_text(node['latex'])
self.end_state()
raise nodes.SkipNode
+
def text_visit_eqref(self, node):
self.add_text(node['target'])
raise nodes.SkipNode
@@ -123,11 +130,15 @@ def man_visit_math(self, node):
self.body.append(node['latex'])
raise nodes.SkipNode
+
def man_visit_displaymath(self, node):
self.visit_centered(node)
+
+
def man_depart_displaymath(self, node):
self.depart_centered(node)
+
def man_visit_eqref(self, node):
self.body.append(node['target'])
raise nodes.SkipNode
@@ -137,14 +148,18 @@ def texinfo_visit_math(self, node):
self.body.append('@math{' + self.escape_arg(node['latex']) + '}')
raise nodes.SkipNode
+
def texinfo_visit_displaymath(self, node):
if node.get('label'):
self.add_anchor(node['label'], node)
self.body.append('\n\n@example\n%s\n@end example\n\n' %
self.escape_arg(node['latex']))
+
+
def texinfo_depart_displaymath(self, node):
pass
+
def texinfo_visit_eqref(self, node):
self.add_xref(node['docname'] + ':' + node['target'],
node['target'], node)
@@ -154,6 +169,7 @@ def texinfo_visit_eqref(self, node):
def html_visit_eqref(self, node):
self.body.append('' % node['target'])
+
def html_depart_eqref(self, node):
self.body.append('')
@@ -177,23 +193,23 @@ def number_equations(app, doctree, docname):
def setup_math(app, htmlinlinevisitors, htmldisplayvisitors):
app.add_node(math,
- latex=(latex_visit_math, None),
- text=(text_visit_math, None),
- man=(man_visit_math, None),
- texinfo=(texinfo_visit_math, None),
- html=htmlinlinevisitors)
+ latex=(latex_visit_math, None),
+ text=(text_visit_math, None),
+ man=(man_visit_math, None),
+ texinfo=(texinfo_visit_math, None),
+ html=htmlinlinevisitors)
app.add_node(displaymath,
- latex=(latex_visit_displaymath, None),
- text=(text_visit_displaymath, None),
- man=(man_visit_displaymath, man_depart_displaymath),
- texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
- html=htmldisplayvisitors)
+ latex=(latex_visit_displaymath, None),
+ text=(text_visit_displaymath, None),
+ man=(man_visit_displaymath, man_depart_displaymath),
+ texinfo=(texinfo_visit_displaymath, texinfo_depart_displaymath),
+ html=htmldisplayvisitors)
app.add_node(eqref,
- latex=(latex_visit_eqref, None),
- text=(text_visit_eqref, None),
- man=(man_visit_eqref, None),
- texinfo=(texinfo_visit_eqref, None),
- html=(html_visit_eqref, html_depart_eqref))
+ latex=(latex_visit_eqref, None),
+ text=(text_visit_eqref, None),
+ man=(man_visit_eqref, None),
+ texinfo=(texinfo_visit_eqref, None),
+ html=(html_visit_eqref, html_depart_eqref))
app.add_role('math', math_role)
app.add_role('eq', eq_role)
app.add_directive('math', MathDirective)
diff --git a/sphinx/ext/mathjax.py b/sphinx/ext/mathjax.py
index 26d1e2aa1..e967cd75e 100644
--- a/sphinx/ext/mathjax.py
+++ b/sphinx/ext/mathjax.py
@@ -25,6 +25,7 @@ def html_visit_math(self, node):
self.builder.config.mathjax_inline[1] + '')
raise nodes.SkipNode
+
def html_visit_displaymath(self, node):
self.body.append(self.starttag(node, 'div', CLASS='math'))
if node['nowrap']:
@@ -52,6 +53,7 @@ def html_visit_displaymath(self, node):
self.body.append('\n')
raise nodes.SkipNode
+
def builder_inited(app):
if not app.config.mathjax_path:
raise ExtensionError('mathjax_path config value must be set for the '
diff --git a/sphinx/ext/pngmath.py b/sphinx/ext/pngmath.py
index 374b7ab32..b0d3fafbb 100644
--- a/sphinx/ext/pngmath.py
+++ b/sphinx/ext/pngmath.py
@@ -28,6 +28,7 @@ from sphinx.util.osutil import ensuredir, ENOENT, cd
from sphinx.util.pycompat import sys_encoding
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
+
class MathExtError(SphinxError):
category = 'Math extension error'
@@ -67,6 +68,7 @@ DOC_BODY_PREVIEW = r'''
depth_re = re.compile(br'\[\d+ depth=(-?\d+)\]')
+
def render_math(self, math):
"""Render the LaTeX math expression *math* using latex and dvipng.
@@ -166,6 +168,7 @@ def render_math(self, math):
return relfn, depth
+
def cleanup_tempdir(app, exc):
if exc:
return
@@ -176,11 +179,13 @@ def cleanup_tempdir(app, exc):
except Exception:
pass
+
def get_tooltip(self, node):
if self.builder.config.pngmath_add_tooltips:
return ' alt="%s"' % self.encode(node['latex']).strip()
return ''
+
def html_visit_math(self, node):
try:
fname, depth = render_math(self, '$'+node['latex']+'$')
@@ -202,6 +207,7 @@ def html_visit_math(self, node):
self.body.append(c + '/>')
raise nodes.SkipNode
+
def html_visit_displaymath(self, node):
if node['nowrap']:
latex = node['latex']
@@ -224,8 +230,8 @@ def html_visit_displaymath(self, node):
self.body.append('%s
\n' %
self.encode(node['latex']).strip())
else:
- self.body.append(('
\n')
+ self.body.append(('
\n')
raise nodes.SkipNode
diff --git a/sphinx/ext/todo.py b/sphinx/ext/todo.py
index 2e91c9eaf..6f4d366c7 100644
--- a/sphinx/ext/todo.py
+++ b/sphinx/ext/todo.py
@@ -20,8 +20,13 @@ from sphinx.environment import NoUri
from sphinx.util.nodes import set_source_info
from sphinx.util.compat import Directive, make_admonition
-class todo_node(nodes.Admonition, nodes.Element): pass
-class todolist(nodes.General, nodes.Element): pass
+
+class todo_node(nodes.Admonition, nodes.Element):
+ pass
+
+
+class todolist(nodes.General, nodes.Element):
+ pass
class Todo(Directive):
@@ -112,7 +117,7 @@ def process_todo_nodes(app, doctree, fromdocname):
para = nodes.paragraph(classes=['todo-source'])
description = _('(The <> is located in '
' %s, line %d.)') % \
- (todo_info['source'], todo_info['lineno'])
+ (todo_info['source'], todo_info['lineno'])
desc1 = description[:description.find('<<')]
desc2 = description[description.find('>>')+2:]
para += nodes.Text(desc1, desc1)
@@ -161,9 +166,11 @@ def merge_info(app, env, docnames, other):
def visit_todo_node(self, node):
self.visit_admonition(node)
+
def depart_todo_node(self, node):
self.depart_admonition(node)
+
def setup(app):
app.add_config_value('todo_include_todos', False, 'html')
diff --git a/sphinx/ext/viewcode.py b/sphinx/ext/viewcode.py
index d213430a9..a79078b50 100644
--- a/sphinx/ext/viewcode.py
+++ b/sphinx/ext/viewcode.py
@@ -155,8 +155,8 @@ def collect_pages(app):
backlink = urito(pagename, docname) + '#' + refname + '.' + name
lines[start] = (
'%s' % (name, backlink, _('[docs]'))
- + lines[start])
+ 'href="%s">%s' % (name, backlink, _('[docs]')) +
+ lines[start])
lines[min(end - 1, maxindex)] += '
'
# try to find parents (for submodules)
parents = []