How to use the sphinx.errors.SphinxError function in Sphinx

To help you get started, we’ve selected a few Sphinx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdolab / OpenAeroStruct / openaerostruct / docs / _exts / embed_code.py View on Github external
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)
github Source-Python-Dev-Team / Source.Python / addons / source-python / packages / site-packages / sphinx / ext / pngmath.py View on Github external
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}
github bokeh / bokeh / bokeh / sphinxext / bokeh_palette_group.py View on Github external
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 &lt; 30]
        html = PALETTE_GROUP_DETAIL.render(name=name, numbers=numbers, palettes=palettes)
        self.body.append(html)
    self.body.append('</div></div>')
    raise nodes.SkipNode
github QubesOS / qubes-core-admin-client / qubesadmin / tools / dochelpers.py View on Github external
# 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))
github rochacbruno / dynaconf / docs / customexts / aafig-pre-sphinx-trans.py View on Github external
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)
github useblocks / sphinxcontrib-needs / sphinxcontrib / needs / api / exceptions.py View on Github external
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
github sphinx-doc / sphinx / sphinx / errors.py View on Github external
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
github sphinx-doc / sphinx / sphinx / ext / pngmath.py View on Github external
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}
github sphinx-doc / sphinx / sphinx / writers / latex.py View on Github external
%(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
github Source-Python-Dev-Team / Source.Python / addons / source-python / packages / site-packages / sphinx / util / i18n.py View on Github external
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)