Python sphinx 模块,errors() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用sphinx.errors()

项目:qubes-core-admin-client    作者:QubesOS    | 项目源码 | 文件源码
def check_undocumented_arguments(self, ignored_options=None):
        ''' Call this to check if any undocumented arguments are left.

            While the documentation talks about a
            'SparseNodeVisitor.depart_document()' function, this function does
            not exists. (For details see implementation of
            :py:method:`NodeVisitor.dispatch_departure()`) So we need to
            manually call this.
        '''
        if ignored_options is None:
            ignored_options = set()
        left_over_args = self.args - ignored_options
        if left_over_args:
            raise sphinx.errors.SphinxError(
                'Undocumented arguments for command {!r}: {!r}'.format(
                    self.command, ', '.join(sorted(left_over_args))))
项目:qubes-core-admin-client    作者:QubesOS    | 项目源码 | 文件源码
def visit_section(self, node):
        ''' Checks if the visited sub-command section nodes exists and it
            options are in sync.

            Uses :py:class:`OptionsCheckVisitor` for checking
            sub-commands options
        '''
        # 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))
项目:qubes-core-admin-client    作者:QubesOS    | 项目源码 | 文件源码
def visit_desc_name(self, node):
        ''' Checks if the option is defined `self.args` '''
        if not isinstance(node[0], docutils.nodes.Text):
            raise sphinx.errors.SphinxError('first child should be Text')

        arg = str(node[0])
        try:
            self.args.remove(arg)
        except KeyError:
            raise sphinx.errors.SphinxError(
                'No such argument for {!r}: {!r}'.format(self.command, arg))
项目:qubes-core-admin-client    作者:QubesOS    | 项目源码 | 文件源码
def check_undocumented_sub_commands(self):
        ''' Call this to check if any undocumented sub_commands are left.

            While the documentation talks about a
            'SparseNodeVisitor.depart_document()' function, this function does
            not exists. (For details see implementation of
            :py:method:`NodeVisitor.dispatch_departure()`) So we need to
            manually call this.
        '''
        if self.sub_commands:
            raise sphinx.errors.SphinxError(
                'Undocumented commands for {!r}: {!r}'.format(
                    self.command, ', '.join(sorted(self.sub_commands.keys()))))
项目:qubes-core-admin-client    作者:QubesOS    | 项目源码 | 文件源码
def __init__(self, app, command, document):
        docutils.nodes.SparseNodeVisitor.__init__(self, document)
        try:
            parser = qubesadmin.tools.get_parser_for_command(command)
        except ImportError:
            app.warn('cannot import module for command')
            self.parser = None
            return
        except AttributeError:
            raise sphinx.errors.SphinxError('cannot find parser in module')

        self.command = command
        self.parser = parser
        self.options = set()
        self.sub_commands = {}
        self.app = app

        # pylint: disable=protected-access
        for action in parser._actions:
            if action.help == argparse.SUPPRESS:
                continue

            if issubclass(action.__class__,
                          qubesadmin.tools.AliasedSubParsersAction):
                for cmd, cmd_parser in action._name_parser_map.items():
                    self.sub_commands[cmd] = set()
                    for sub_action in cmd_parser._actions:
                        if sub_action.help != argparse.SUPPRESS:
                            self.sub_commands[cmd].update(
                                sub_action.option_strings)
            else:
                self.options.update(action.option_strings)
项目:deviation-manual    作者:DeviationTX    | 项目源码 | 文件源码
def init_math(app):
    """
        This is a dummy math extension.

        It's a hack, but if you want math in a PDF via pdfbuilder, and don't want to
        enable pngmath or jsmath, then enable this one.

        :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
        :license: BSD, see LICENSE for details.
    """
    from sphinx.errors import SphinxError
    try:
        # Sphinx 0.6.4 and later
        from sphinx.ext.mathbase import setup_math as mathbase_setup
    except ImportError:
        try:
            # Sphinx 0.6.3
            from sphinx.ext.mathbase import setup as mathbase_setup
        except ImportError, e:
            log.error('Error importing sphinx math extension: %s', e)

    class MathExtError(SphinxError):
        category = 'Math extension error'


    def html_visit_math(self, node):
        self.body.append(node['latex'])
        raise nodes.SkipNode

    def html_visit_displaymath(self, node):
        self.body.append(node['latex'])
        raise nodes.SkipNode

    mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None))