Python sphinx.util() Examples

The following are 5 code examples of sphinx.util(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module sphinx , or try the search function .
Example #1
Source File: dochelpers.py    From qubes-core-admin with GNU Lesser General Public License v2.1 6 votes vote down vote up
def setup(app):
    app.add_role('ticket', ticket)
    app.add_config_value(
        'ticket_base_uri',
        'https://api.github.com/repos/QubesOS/qubes-issues/issues/{number}',
        'env')
    app.add_config_value('break_to_pdb', False, 'env')
    app.add_node(versioncheck,
                 html=(visit, depart),
                 man=(visit, depart))
    app.add_directive('versioncheck', VersionCheck)

    fdesc = sphinx.util.docfields.GroupedField('parameter', label='Parameters',
                                               names=['param'],
                                               can_collapse=True)
    app.add_object_type('event', 'event', 'pair: %s; event', parse_event,
                        doc_field_types=[fdesc])

    app.connect('doctree-resolved', break_to_pdb)
    app.connect('doctree-resolved', check_man_args)

# vim: ts=4 sw=4 et 
Example #2
Source File: sphinx_compatibility.py    From sphinx-gallery with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _app_get_logger(name):
    class SphinxLoggerAdapter:
        def _color_to_func(self, kwargs, default=''):
            return getattr(sphinx.util.console,
                           kwargs.pop('color', default),
                           None)

        def error(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs, default='red')
            return _app.warn(colorfunc(msg), **kwargs)

        def critical(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs, default='red')
            return _app.warn(colorfunc(msg), **kwargs)

        def warning(self, msg, *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs)
            if colorfunc:
                # colorfunc is a valid kwarg in 1.5, but not older, so we just
                # apply it ourselves.
                msg = colorfunc(msg)
            return _app.warn(msg, **kwargs)

        def info(self, msg='', *args, **kwargs):
            msg = msg % args
            colorfunc = self._color_to_func(kwargs)
            if colorfunc:
                msg = colorfunc(msg)
            return _app.info(msg, **kwargs)

        def verbose(self, msg, *args, **kwargs):
            return _app.verbose(msg, *args, **kwargs)

        def debug(self, msg, *args, **kwargs):
            return _app.debug(msg, *args, **kwargs)

    return SphinxLoggerAdapter() 
Example #3
Source File: sphinx_compatibility.py    From sphinx-gallery with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _app_status_iterator(iterable, summary, **kwargs):
    global _app

    color = kwargs.pop('color', None)
    if color is not None:
        kwargs['colorfunc'] = getattr(sphinx.util.console, color)

    for item in _app.status_iterator(iterable, summary, **kwargs):
        yield item 
Example #4
Source File: pdfbuilder.py    From rst2pdf with MIT License 5 votes vote down vote up
def init(self):
        self.docnames = []
        self.document_data = []
        self.sphinx_logger = sphinx.util.logging.getLogger(__name__) 
Example #5
Source File: need_part.py    From sphinxcontrib-needs with MIT License 4 votes vote down vote up
def update_need_with_parts(env, need, part_nodes):
    for part_node in part_nodes:
        content = part_node.children[0].children[0]  # ->inline->Text
        result = part_pattern.match(content)
        if result is not None:
            inline_id = result.group(1)
            part_content = result.group(2)
        else:
            part_content = content
            inline_id = hashlib.sha1(part_content.encode("UTF-8")).hexdigest().upper()[:3]

        if 'parts' not in need.keys():
            need['parts'] = {}

        if inline_id in need['parts'].keys():
            log.warning("part_need id {} in need {} is already taken. need_part may get overridden.".format(
                inline_id, need['id']))

        need['parts'][inline_id] = {
            'id': inline_id,
            'content': part_content,
            'document': need["docname"],
            'links_back': [],
            'is_part': True,
            'is_need': False,
            'links': [],
        }

        part_id_ref = '{}.{}'.format(need['id'], inline_id)
        part_id_show = inline_id
        part_node['reftarget'] = part_id_ref

        part_link_text = ' {}'.format(part_id_show)
        part_link_node = nodes.Text(part_link_text, part_link_text)
        part_text_node = nodes.Text(part_content, part_content)

        from sphinx.util.nodes import make_refnode

        part_ref_node = make_refnode(env.app.builder,
                                     need['docname'],
                                     need['docname'],
                                     part_id_ref,
                                     part_link_node)
        part_ref_node["classes"] += ['needs-id']

        part_node.children = []
        node_need_part_line = nodes.inline(ids=[part_id_ref], classes=["need-part"])
        node_need_part_line.append(part_text_node)
        node_need_part_line.append(part_ref_node)
        part_node.append(node_need_part_line)