mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Minor PEP8 cleanup.
This commit is contained in:
parent
c5cc2a8cf9
commit
df53ece2f7
@ -25,6 +25,7 @@ class desc(nodes.Admonition, nodes.Element):
|
||||
contains one or more ``desc_signature`` and a ``desc_content``.
|
||||
"""
|
||||
|
||||
|
||||
class desc_signature(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for object signatures.
|
||||
|
||||
@ -39,33 +40,42 @@ class desc_addname(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
# compatibility alias
|
||||
desc_classname = desc_addname
|
||||
|
||||
|
||||
class desc_type(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for return types or object type names."""
|
||||
|
||||
|
||||
class desc_returns(desc_type):
|
||||
"""Node for a "returns" annotation (a la -> in Python)."""
|
||||
def astext(self):
|
||||
return ' -> ' + nodes.TextElement.astext(self)
|
||||
|
||||
|
||||
class desc_name(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for the main object name."""
|
||||
|
||||
|
||||
class desc_parameterlist(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for a general parameter list."""
|
||||
child_text_separator = ', '
|
||||
|
||||
|
||||
class desc_parameter(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for a single parameter."""
|
||||
|
||||
|
||||
class desc_optional(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for marking optional parts of the parameter list."""
|
||||
child_text_separator = ', '
|
||||
|
||||
def astext(self):
|
||||
return '[' + nodes.TextElement.astext(self) + ']'
|
||||
|
||||
|
||||
class desc_annotation(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for signature annotations (not Python 3-style annotations)."""
|
||||
|
||||
|
||||
class desc_content(nodes.General, nodes.Element):
|
||||
"""Node for object description content.
|
||||
|
||||
@ -82,15 +92,18 @@ class versionmodified(nodes.Admonition, nodes.TextElement):
|
||||
directives.
|
||||
"""
|
||||
|
||||
|
||||
class seealso(nodes.Admonition, nodes.Element):
|
||||
"""Custom "see also" admonition."""
|
||||
|
||||
|
||||
class productionlist(nodes.Admonition, nodes.Element):
|
||||
"""Node for grammar production lists.
|
||||
|
||||
Contains ``production`` nodes.
|
||||
"""
|
||||
|
||||
|
||||
class production(nodes.Part, nodes.Inline, nodes.TextElement):
|
||||
"""Node for a single grammar production rule."""
|
||||
|
||||
@ -107,26 +120,33 @@ class index(nodes.Invisible, nodes.Inline, nodes.TextElement):
|
||||
*entrytype* is one of "single", "pair", "double", "triple".
|
||||
"""
|
||||
|
||||
|
||||
class centered(nodes.Part, nodes.TextElement):
|
||||
"""Deprecated."""
|
||||
|
||||
|
||||
class acks(nodes.Element):
|
||||
"""Special node for "acks" lists."""
|
||||
|
||||
|
||||
class hlist(nodes.Element):
|
||||
"""Node for "horizontal lists", i.e. lists that should be compressed to
|
||||
take up less vertical space.
|
||||
"""
|
||||
|
||||
|
||||
class hlistcol(nodes.Element):
|
||||
"""Node for one column in a horizontal list."""
|
||||
|
||||
|
||||
class compact_paragraph(nodes.paragraph):
|
||||
"""Node for a compact paragraph (which never makes a <p> node)."""
|
||||
|
||||
|
||||
class glossary(nodes.Element):
|
||||
"""Node to insert a glossary."""
|
||||
|
||||
|
||||
class only(nodes.Element):
|
||||
"""Node for "only" directives (conditional inclusion based on tags)."""
|
||||
|
||||
@ -136,14 +156,17 @@ class only(nodes.Element):
|
||||
class start_of_file(nodes.Element):
|
||||
"""Node to mark start of a new file, used in the LaTeX builder only."""
|
||||
|
||||
|
||||
class highlightlang(nodes.Element):
|
||||
"""Inserted to set the highlight language and line number options for
|
||||
subsequent code blocks.
|
||||
"""
|
||||
|
||||
|
||||
class tabular_col_spec(nodes.Element):
|
||||
"""Node for specifying tabular columns, used for LaTeX output."""
|
||||
|
||||
|
||||
class meta(nodes.Special, nodes.PreBibliographic, nodes.Element):
|
||||
"""Node for meta directive -- same as docutils' standard meta node,
|
||||
but pickleable.
|
||||
@ -160,22 +183,27 @@ class pending_xref(nodes.Inline, nodes.Element):
|
||||
BuildEnvironment.resolve_references.
|
||||
"""
|
||||
|
||||
|
||||
class download_reference(nodes.reference):
|
||||
"""Node for download references, similar to pending_xref."""
|
||||
|
||||
|
||||
class literal_emphasis(nodes.emphasis):
|
||||
"""Node that behaves like `emphasis`, but further text processors are not
|
||||
applied (e.g. smartypants for HTML output).
|
||||
"""
|
||||
|
||||
|
||||
class literal_strong(nodes.strong):
|
||||
"""Node that behaves like `strong`, but further text processors are not
|
||||
applied (e.g. smartypants for HTML output).
|
||||
"""
|
||||
|
||||
|
||||
class abbreviation(nodes.Inline, nodes.TextElement):
|
||||
"""Node for abbreviations with explanations."""
|
||||
|
||||
|
||||
class termsep(nodes.Structural, nodes.Element):
|
||||
"""Separates two terms within a <term> node."""
|
||||
|
||||
|
@ -88,7 +88,7 @@ def create_module_file(package, module, opts):
|
||||
text = format_heading(1, '%s module' % module)
|
||||
else:
|
||||
text = ''
|
||||
#text += format_heading(2, ':mod:`%s` Module' % module)
|
||||
# text += format_heading(2, ':mod:`%s` Module' % module)
|
||||
text += format_directive(module, package)
|
||||
write_file(makename(package, module), text, opts)
|
||||
|
||||
|
@ -200,8 +200,8 @@ class Sphinx(object):
|
||||
else:
|
||||
try:
|
||||
self.info(bold('loading pickled environment... '), nonl=True)
|
||||
self.env = BuildEnvironment.frompickle(self.config,
|
||||
path.join(self.doctreedir, ENV_PICKLE_FILENAME))
|
||||
self.env = BuildEnvironment.frompickle(
|
||||
self.config, path.join(self.doctreedir, ENV_PICKLE_FILENAME))
|
||||
self.env.domains = {}
|
||||
for domain in self.domains.keys():
|
||||
# this can raise if the data version doesn't fit
|
||||
|
@ -503,7 +503,8 @@ class BuildEnvironment:
|
||||
"""Custom decoding error handler that warns and replaces."""
|
||||
linestart = error.object.rfind(b'\n', 0, error.start)
|
||||
lineend = error.object.find(b'\n', error.start)
|
||||
if lineend == -1: lineend = len(error.object)
|
||||
if lineend == -1:
|
||||
lineend = len(error.object)
|
||||
lineno = error.object.count(b'\n', 0, error.start) + 1
|
||||
self.warn(self.docname, 'undecodable source characters, '
|
||||
'replacing with "?": %r' %
|
||||
|
@ -10,13 +10,16 @@
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import sys, os, time, re
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from os import path
|
||||
from io import open
|
||||
|
||||
TERM_ENCODING = getattr(sys.stdin, 'encoding', None)
|
||||
|
||||
#try to import readline, unix specific enhancement
|
||||
# try to import readline, unix specific enhancement
|
||||
try:
|
||||
import readline
|
||||
if readline.__doc__ and 'libedit' in readline.__doc__:
|
||||
@ -972,17 +975,20 @@ def mkdir_p(dir):
|
||||
class ValidationError(Exception):
|
||||
"""Raised for validation errors."""
|
||||
|
||||
|
||||
def is_path(x):
|
||||
x = path.expanduser(x)
|
||||
if path.exists(x) and not path.isdir(x):
|
||||
raise ValidationError("Please enter a valid path name.")
|
||||
return x
|
||||
|
||||
|
||||
def nonempty(x):
|
||||
if not x:
|
||||
raise ValidationError("Please enter some text.")
|
||||
return x
|
||||
|
||||
|
||||
def choice(*l):
|
||||
def val(x):
|
||||
if x not in l:
|
||||
@ -990,17 +996,20 @@ def choice(*l):
|
||||
return x
|
||||
return val
|
||||
|
||||
|
||||
def boolean(x):
|
||||
if x.upper() not in ('Y', 'YES', 'N', 'NO'):
|
||||
raise ValidationError("Please enter either 'y' or 'n'.")
|
||||
return x.upper() in ('Y', 'YES')
|
||||
|
||||
|
||||
def suffix(x):
|
||||
if not (x[0:1] == '.' and len(x) > 1):
|
||||
raise ValidationError("Please enter a file suffix, "
|
||||
"e.g. '.rst' or '.txt'.")
|
||||
return x
|
||||
|
||||
|
||||
def ok(x):
|
||||
return x
|
||||
|
||||
|
@ -236,6 +236,7 @@ def indexmarkup_role(typ, rawtext, text, lineno, inliner,
|
||||
|
||||
_amp_re = re.compile(r'(?<!&)&(?![&\s])')
|
||||
|
||||
|
||||
def menusel_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
text = utils.unescape(text)
|
||||
if typ == 'menuselection':
|
||||
@ -264,6 +265,7 @@ def menusel_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
|
||||
_litvar_re = re.compile('{([^}]+)}')
|
||||
|
||||
|
||||
def emph_literal_role(typ, rawtext, text, lineno, inliner,
|
||||
options={}, content=[]):
|
||||
text = utils.unescape(text)
|
||||
@ -282,6 +284,7 @@ def emph_literal_role(typ, rawtext, text, lineno, inliner,
|
||||
|
||||
_abbr_re = re.compile('\((.*)\)$', re.S)
|
||||
|
||||
|
||||
def abbr_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
|
||||
text = utils.unescape(text)
|
||||
m = _abbr_re.search(text)
|
||||
|
@ -30,6 +30,7 @@ from sphinx.errors import ThemeError
|
||||
NODEFAULT = object()
|
||||
THEMECONF = 'theme.conf'
|
||||
|
||||
|
||||
class Theme(object):
|
||||
"""
|
||||
Represents the theme chosen in the configuration.
|
||||
@ -94,7 +95,8 @@ class Theme(object):
|
||||
self.themedir = tempfile.mkdtemp('sxt')
|
||||
self.themedir_created = True
|
||||
for name in tinfo.namelist():
|
||||
if name.endswith('/'): continue
|
||||
if name.endswith('/'):
|
||||
continue
|
||||
dirname = path.dirname(name)
|
||||
if not path.isdir(path.join(self.themedir, dirname)):
|
||||
os.makedirs(path.join(self.themedir, dirname))
|
||||
|
@ -34,6 +34,7 @@ default_substitutions = set([
|
||||
'today',
|
||||
])
|
||||
|
||||
|
||||
class DefaultSubstitutions(Transform):
|
||||
"""
|
||||
Replace some substitutions if they aren't defined in the document.
|
||||
@ -89,7 +90,7 @@ class HandleCodeBlocks(Transform):
|
||||
in node.children):
|
||||
node.replace_self(node.children)
|
||||
# combine successive doctest blocks
|
||||
#for node in self.document.traverse(nodes.doctest_block):
|
||||
# for node in self.document.traverse(nodes.doctest_block):
|
||||
# if node not in node.parent.children:
|
||||
# continue
|
||||
# parindex = node.parent.index(node)
|
||||
@ -173,7 +174,7 @@ class Locale(Transform):
|
||||
|
||||
parser = RSTParser()
|
||||
|
||||
#phase1: replace reference ids with translated names
|
||||
# phase1: replace reference ids with translated names
|
||||
for node, msg in extract_messages(self.document):
|
||||
msgstr = catalog.gettext(msg)
|
||||
# XXX add marker to untranslated parts
|
||||
@ -281,8 +282,7 @@ class Locale(Transform):
|
||||
node.children = patch.children
|
||||
node['translated'] = True
|
||||
|
||||
|
||||
#phase2: translation
|
||||
# phase2: translation
|
||||
for node, msg in extract_messages(self.document):
|
||||
if node.get('translated', False):
|
||||
continue
|
||||
@ -315,6 +315,7 @@ class Locale(Transform):
|
||||
def is_autonumber_footnote_ref(node):
|
||||
return isinstance(node, nodes.footnote_reference) and \
|
||||
node.get('auto') == 1
|
||||
|
||||
def list_replace_or_append(lst, old, new):
|
||||
if old in lst:
|
||||
lst[lst.index(old)] = new
|
||||
@ -404,6 +405,7 @@ class Locale(Transform):
|
||||
if len(old_refs) != len(new_refs):
|
||||
env.warn_node('inconsistent term references in '
|
||||
'translated message', node)
|
||||
|
||||
def get_ref_key(node):
|
||||
case = node["refdomain"], node["reftype"]
|
||||
if case == ('std', 'term'):
|
||||
|
Loading…
Reference in New Issue
Block a user