Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
except Exception as err:
raise SphinxError(str(err))
is_test = class_ is not None and issubclass(class_, unittest.TestCase)
shows_plot = '.show(' in source
if 'layout' in self.options:
layout = [s.strip() for s in self.options['layout'].split(',')]
else:
layout = ['code']
if len(layout) > len(set(layout)):
raise SphinxError("No duplicate layout entries allowed.")
bad = [n for n in layout if n not in allowed_layouts]
if bad:
raise SphinxError("The following layout options are invalid: %s" % bad)
if 'interleave' in layout and ('code' in layout or 'output' in layout):
raise SphinxError("The interleave option is mutually exclusive to the code "
"and print options.")
remove_docstring = 'strip-docstrings' in self.options
do_run = 'output' in layout or 'interleave' in layout or 'plot' in layout
if 'plot' in layout:
plot_dir = os.getcwd()
plot_fname = 'doc_plot_%d.png' % _plot_count
_plot_count += 1
plot_file_abs = os.path.join(os.path.abspath(plot_dir), plot_fname)
if os.path.isfile(plot_file_abs):
# remove any existing plot file
os.remove(plot_file_abs)
from os import path
from subprocess import Popen, PIPE
from hashlib import sha1
from six import text_type
from docutils import nodes
import sphinx
from sphinx.errors import SphinxError, ExtensionError
from sphinx.util.png import read_png_depth, write_png_depth
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'
def __init__(self, msg, stderr=None, stdout=None):
if stderr:
msg += '\n[stderr]\n' + stderr.decode(sys_encoding, 'replace')
if stdout:
msg += '\n[stdout]\n' + stdout.decode(sys_encoding, 'replace')
SphinxError.__init__(self, msg)
DOC_HEAD = r'''
\documentclass[12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
def html_visit_bokeh_palette_group(self, node):
self.body.append('<div class="container-fluid"><div class="row">"')
group = getattr(bp, node['group'], None)
if not isinstance(group, dict):
raise SphinxError("invalid palette group name %r" % node['group'])
names = sorted(group)
for name in names:
palettes = group[name]
# arbitrary cuttoff here, idea is to not show large (e.g 256 length) palettes
numbers = [x for x in sorted(palettes) if x < 30]
html = PALETTE_GROUP_DETAIL.render(name=name, numbers=numbers, palettes=palettes)
self.body.append(html)
self.body.append('</div></div>')
raise nodes.SkipNode
# pylint: disable=no-self-use
title = str(node[0][0])
if title.upper() == SUBCOMMANDS_TITLE:
return
sub_cmd = self.command + ' ' + title
try:
args = self.sub_commands[title]
options_visitor = OptionsCheckVisitor(sub_cmd, args, self.document)
node.walkabout(options_visitor)
options_visitor.check_undocumented_arguments(
{'--help', '--quiet', '--verbose', '-h', '-q', '-v'})
del self.sub_commands[title]
except KeyError:
raise sphinx.errors.SphinxError(
'No such sub-command {!r}'.format(sub_cmd))
for (k, v) in visitor.builder.config.aafig_default_options.items():
if k not in options:
options[k] = v
return options
def get_basename(text, options, prefix='aafig'):
options = options.copy()
if 'format' in options:
del options['format']
hashkey = text.encode('utf-8') + str(options)
id = sha(hashkey).hexdigest()
return '%s-%s' % (prefix, id)
class AafigError(SphinxError):
category = 'aafig error'
class AafigTransform(transforms.Transform):
default_priority = 500 # TODO
def apply(self):
current_node = self.startnode
details = current_node.details
image_node = details['image_node']
options = details['aafigure_options'].copy()
text = current_node.rawsource
#merge_defaults(options, self)
# XXX: this is an ugly hack to find out the writer being used
print('>>>>>>>>>>>>>>>>>>>>>', self.document.transformer.components)
pass
class NeedsDuplicatedId(SphinxError):
pass
class NeedsStatusNotAllowed(SphinxError):
pass
class NeedsTagNotAllowed(SphinxError):
pass
class NeedsInvalidException(SphinxError):
pass
class NeedsInvalidOption(SphinxError):
pass
class NeedsTemplateException(SphinxError):
pass
class NeedsInvalidFilter(SphinxError):
pass
class ConfigError(SphinxError):
"""Configuration error."""
category = 'Configuration error'
class DocumentError(SphinxError):
"""Document error."""
category = 'Document error'
class ThemeError(SphinxError):
"""Theme error."""
category = 'Theme error'
class VersionRequirementError(SphinxError):
"""Incompatible Sphinx version error."""
category = 'Sphinx version error'
class SphinxParallelError(SphinxError):
"""Sphinx parallel build error."""
category = 'Sphinx parallel build error'
def __init__(self, message, traceback):
# type: (str, Any) -> None
self.message = message
self.traceback = traceback
def __str__(self):
# type: () -> str
from sphinx.ext.mathbase import get_node_equation_number
from sphinx.ext.mathbase import setup_math as mathbase_setup, wrap_displaymath
from sphinx.util import logging
from sphinx.util.osutil import ensuredir, ENOENT, cd
from sphinx.util.png import read_png_depth, write_png_depth
from sphinx.util.pycompat import sys_encoding
if TYPE_CHECKING:
from typing import Any, Dict, Tuple # NOQA
from sphinx.application import Sphinx # NOQA
from sphinx.ext.mathbase import math as math_node, displaymath # NOQA
logger = logging.getLogger(__name__)
class MathExtError(SphinxError):
category = 'Math extension error'
def __init__(self, msg, stderr=None, stdout=None):
# type: (unicode, unicode, unicode) -> None
if stderr:
msg += '\n[stderr]\n' + stderr.decode(sys_encoding, 'replace')
if stdout:
msg += '\n[stdout]\n' + stdout.decode(sys_encoding, 'replace')
SphinxError.__init__(self, msg)
DOC_HEAD = r'''
\documentclass[12pt]{article}
\usepackage[utf8x]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
%(tableofcontents)s
'''
FOOTER = r'''
%(footer)s
\renewcommand{\indexname}{%(modindexname)s}
%(printmodindex)s
\renewcommand{\indexname}{%(indexname)s}
%(printindex)s
\end{document}
'''
class collected_footnote(nodes.footnote):
"""Footnotes that are collected are assigned this class."""
class UnsupportedError(SphinxError):
category = 'Markup is unsupported in LaTeX'
class LaTeXWriter(writers.Writer):
supported = ('sphinxlatex',)
settings_spec = ('LaTeX writer options', '', (
('Document name', ['--docname'], {'default': ''}),
('Document class', ['--docclass'], {'default': 'manual'}),
('Author', ['--author'], {'default': ''}),
))
settings_defaults = {}
output = None
def get_image_filename_for_language(filename, env):
if not env.config.language:
return filename
filename_format = env.config.figure_language_filename
root, ext = path.splitext(filename)
try:
return filename_format.format(root=root, ext=ext,
language=env.config.language)
except KeyError as exc:
raise SphinxError('Invalid figure_language_filename: %r' % exc)