Exemplo n.º 1
0
def setup(app):
    app.add_directive_to_domain(DOMAIN, 'templatetag', TemplateTag)
    app.add_role_to_domain(DOMAIN, 'ttag', PyXRefRole())
    app.add_directive_to_domain(DOMAIN, 'templatefilter', TemplateTag)
    app.add_role_to_domain(DOMAIN, 'tfilter', PyXRefRole())
    app.add_autodocumenter(TemplateTagDocumenter)
    app.add_autodocumenter(TemplateFilterDocumenter)
Exemplo n.º 2
0
def setup(app: Sphinx) -> None:
    app.setup_extension('sphinx.ext.autodoc')
    app.add_autodocumenter(QtSignalDocumenter)
    app.add_autodocumenter(QtSlotDocumenter)
    app.add_autodocumenter(QtPropertyDocumenter)

    app.setup_extension('sphinx.directives')
    sig_role = PyXRefRole()
    slot_role = PyXRefRole()
    prop_role = PyXRefRole()
    sig_obj_type = ObjType(_('QtSignal'), 'signal', 'attr', 'obj')
    slot_obj_type = ObjType(_('QtSlot'), 'slot', 'meth', 'obj')
    prop_obj_type = ObjType(_('QtProperty'), 'qtproperty', 'attr', 'obj')

    app.add_directive_to_domain('py', 'qtsignal', QtSignalDirective)
    app.add_directive_to_domain('py', 'qtslot', QtSlotDirective)
    app.add_directive_to_domain('py', 'qtproperty', QtPropertyDirective)
    app.add_role_to_domain('py', 'qtsignal', sig_role)
    app.add_role_to_domain('py', 'qtslot', slot_role)
    app.add_role_to_domain('py', 'qtproperty', prop_role)

    object_types = app.registry.domain_object_types.setdefault('py', {})
    object_types['qtsignal'] = sig_obj_type
    object_types['qtslot'] = slot_obj_type
    object_types['qtproperty'] = prop_obj_type

    return {'version': '0.1', 'parallel_read_safe': True}
Exemplo n.º 3
0
def setup(app):
    app.add_directive_to_domain('py', 'interface', PyInterface)
    app.add_role_to_domain('py', 'interface', PyXRefRole())
    app.add_autodocumenter(InterfaceDocumenter)
    app.add_directive_to_domain('py', 'event', PyEvent)
    app.add_role_to_domain('py', 'event', PyXRefRole())
    app.add_autodocumenter(EventDocumenter)
Exemplo n.º 4
0
def setup(app: Sphinx) -> Dict[str, Any]:
    """
	Setup Sphinx Extension.

	:param app:
	"""

    app.registry.domains["py"].object_types["enum"] = ObjType(
        _("enum"), "enum", "class", "obj")
    app.add_directive_to_domain("py", "enum", PyClasslike)
    app.add_role_to_domain("py", "enum", PyXRefRole())

    app.registry.domains["py"].object_types["flag"] = ObjType(
        _("flag"), "flag", "enum", "class", "obj")
    app.add_directive_to_domain("py", "flag", PyClasslike)
    app.add_role_to_domain("py", "flag", PyXRefRole())

    app.add_role_to_domain("py", "enum:mem", PyEnumXRefRole())
    app.add_role_to_domain("py", "enum:member", PyEnumXRefRole())
    app.add_role_to_domain("py", "flag:mem", PyEnumXRefRole())
    app.add_role_to_domain("py", "flag:member", PyEnumXRefRole())

    app.add_autodocumenter(EnumDocumenter)
    app.add_autodocumenter(FlagDocumenter)

    return {
        "version": __version__,
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }
def setup(app: Sphinx) -> SphinxExtMetadata:
    """
	Setup :mod:`sphinx_toolbox.more_autodoc.autonamedtuple`.

	.. versionadded:: 0.8.0

	:param app: The Sphinx application.
	"""

    # Hack to get the docutils tab size, as there doesn't appear to be any other way
    app.setup_extension("sphinx_toolbox.tweaks.tabsize")

    app.registry.domains["py"].object_types["namedtuple"] = ObjType(
        _("namedtuple"), "namedtuple", "class", "obj")
    app.add_directive_to_domain("py", "namedtuple", PyClasslike)
    app.add_role_to_domain("py", "namedtuple", PyXRefRole())

    app.connect("object-description-transform",
                add_fallback_css_class({"namedtuple": "class"}))

    allow_subclass_add(app, NamedTupleDocumenter)

    app.connect("config-inited",
                lambda _, config: add_nbsp_substitution(config))

    return {"parallel_read_safe": True}
def setup(app):
    app.add_transform(LinkParams)
    app.add_transform(ApplyParamPrefix)

    # Make sure that default is are the same as in LinkParams
    # When config changes, the whole env needs to be rebuild since
    # LinkParams is applied while building the doctrees
    app.add_config_value(
        "paramlinks_hyperlink_param",
        HyperlinkStyle.LINK_SYMBOL.name,
        "env",
        [str],
    )

    # PyXRefRole is what the sphinx Python domain uses to set up
    # role nodes like "meth", "func", etc.  It produces a "pending xref"
    # sphinx node along with contextual information.
    app.add_role_to_domain("py", "paramref", PyXRefRole())

    app.connect("autodoc-process-docstring", autodoc_process_docstring)
    app.connect("builder-inited", add_stylesheet)
    app.connect("build-finished", copy_stylesheet)
    app.connect("doctree-read", build_index)
    app.connect("missing-reference", lookup_params)

    return {
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }
Exemplo n.º 7
0
def brianobj_role(role,
                  rawtext,
                  text,
                  lineno,
                  inliner,
                  options={},
                  content=[]):
    """
    A Sphinx role, used as a wrapper for the default `py:obj` role, allowing
    us to use the simple backtick syntax for brian classes/functions without
    having to qualify the package for classes/functions that are available after
    a `from brian2 import *`, e.g `NeuronGroup`.
    Also allows to directly link to preference names using the same syntax.
    """
    if text in prefs:
        linktext = text.replace('_', '-').replace('.', '-')
        text = f'{text} <brian-pref-{linktext}>'
        # Use sphinx's cross-reference role
        xref = XRefRole(warn_dangling=True)
        return xref('std:ref', rawtext, text, lineno, inliner, options,
                    content)
    else:
        if text and (not '~' in text):
            try:
                # A simple class or function name
                if '.' not in text:
                    module = __import__('brian2', fromlist=[str(text)])
                    imported = getattr(module, str(text), None)
                    if getattr(imported, '__module__', None):
                        text = f"~{imported.__module__}.{text}"
                        if inspect.isfunction(imported):
                            text += '()'
                # Possibly a method/classmethod/attribute name
                elif len(text.split('.')) == 2:
                    classname, attrname = text.split('.')
                    # Remove trailing parentheses (will be readded for display)
                    if attrname.endswith('()'):
                        attrname = attrname[:-2]
                    module = __import__('brian2', fromlist=[str(classname)])
                    imported = getattr(module, str(classname), None)
                    if hasattr(imported, '__module__'):
                        # Add trailing parentheses only for methods not for
                        # attributes
                        if inspect.ismethod(
                                getattr(imported, str(attrname), None)):
                            parentheses = '()'
                        else:
                            parentheses = ''

                        text = (
                            f"{classname}.{attrname}{parentheses} "
                            f"<{imported.__module__}.{classname}.{attrname}>")

            except ImportError:
                pass
        role = 'py:obj'
        py_role = PyXRefRole()
        return py_role(role, rawtext, text, lineno, inliner, options, content)
Exemplo n.º 8
0
def setup(app):
    app.add_directive_to_domain('py', 'propertyobj', PropertyObjDirective)
    propertyobj_role = PyXRefRole()
    app.add_role_to_domain('py', 'propertyobj', propertyobj_role)
    return {
        'version': '0.1',
        'parallel_read_safe': True,
        'parallel_write_safe': True,
    }
Exemplo n.º 9
0
def setup(app):
    app.add_directive_to_domain('py', 'event', EventDirective)
    event_role = PyXRefRole()
    app.add_role_to_domain('py', 'event', event_role)
    return {
        'version': '0.1',
        'parallel_read_safe': True,
        'parallel_write_safe': True,
    }
Exemplo n.º 10
0
class EnamlDomain(PythonDomain):
    """Enaml language domain."""
    name = 'enaml'
    label = 'Enaml'
    object_types = {
        'enaml_module': ObjType(l_('enaml module'), 'mod', 'obj'),
        ## 'enaml_defn':      ObjType(l_('enaml built-in'),  'enaml_comp', 'obj'),
        'enaml_decl': ObjType(l_('enaml derived'), 'enaml_comp', 'obj'),
    }

    directives = {
        ## 'enaml_defn':      EnamlDefn,
        'enaml_decl': EnamlDeclaration,
        'enaml_module': PyModule,
    }
    roles = {
        'mod': PyXRefRole(),
        'enaml_comp': PyXRefRole(),
    }
Exemplo n.º 11
0
def setup(app):
    app.setup_extension('sphinx.ext.autodoc')

    app.add_directive_to_domain('py', 'builtinproperty', BuiltinPropertyDirective)
    builtinproperty_role = PyXRefRole()
    app.add_role_to_domain('py', 'builtinproperty', builtinproperty_role)

    app.add_autodocumenter(BuiltinPropertyDocumenter, override=True)
    return {
        'version': '0.1',
        'parallel_read_safe': True,
        'parallel_write_safe': True,
    }
Exemplo n.º 12
0
def setup(app):
    app.add_transform(LinkParams)

    # PyXRefRole is what the sphinx Python domain uses to set up
    # role nodes like "meth", "func", etc.  It produces a "pending xref"
    # sphinx node along with contextual information.
    app.add_role_to_domain("py", "paramref", PyXRefRole())

    app.connect('autodoc-process-docstring', autodoc_process_docstring)
    app.connect('builder-inited', add_stylesheet)
    app.connect('build-finished', copy_stylesheet)
    app.connect('missing-reference', lookup_params)
    app.connect('doctree-read', build_index)
Exemplo n.º 13
0
def setup(app: Sphinx) -> SphinxExtMetadata:
    """
	Setup :mod:`sphinx_toolbox.more_autodoc.autotypeddict`.

	:param app: The Sphinx application.
	"""

    app.registry.domains["py"].object_types["typeddict"] = ObjType(
        "typeddict", "typeddict", "class", "obj")
    app.add_directive_to_domain("py", "typeddict", PyClasslike)
    app.add_role_to_domain("py", "typeddict", PyXRefRole())
    app.connect("object-description-transform",
                add_fallback_css_class({"typeddict": "class"}))

    allow_subclass_add(app, TypedDictDocumenter)

    return {"parallel_read_safe": True}
Exemplo n.º 14
0
def setup(app: Sphinx) -> SphinxExtMetadata:
    """
	Setup :mod:`sphinx_toolbox.more_autodoc.autotypeddict`.

	:param app: The Sphinx app.

	.. versionadded:: 0.5.0
	"""

    app.registry.domains["py"].object_types["typeddict"] = ObjType(
        "typeddict", "typeddict", "class", "obj")
    app.add_directive_to_domain("py", "typeddict", PyClasslike)
    app.add_role_to_domain("py", "typeddict", PyXRefRole())

    allow_subclass_add(app, TypedDictDocumenter)

    return {"parallel_read_safe": True}
def setup(app):
    app.add_transform(LinkParams)
    app.add_transform(ApplyParamPrefix)

    # PyXRefRole is what the sphinx Python domain uses to set up
    # role nodes like "meth", "func", etc.  It produces a "pending xref"
    # sphinx node along with contextual information.
    app.add_role_to_domain("py", "paramref", PyXRefRole())

    app.connect("autodoc-process-docstring", autodoc_process_docstring)
    app.connect("builder-inited", add_stylesheet)
    app.connect("build-finished", copy_stylesheet)
    app.connect("doctree-read", build_index)
    app.connect("missing-reference", lookup_params)
    return {
        "parallel_read_safe": True,
        "parallel_write_safe": True,
    }
Exemplo n.º 16
0
def setup(app: Sphinx) -> Dict[str, Any]:
    """
	Setup :mod:`sphinx_autofixture`.

	:param app: The Sphinx app.
	"""

    app.registry.domains["py"].object_types["fixture"] = ObjType(
        _("fixture"), "fixture", "function", "obj")
    app.add_directive_to_domain("py", "fixture", PyClasslike)
    app.add_role_to_domain("py", "fixture", PyXRefRole())

    app.add_autodocumenter(FixtureDocumenter)

    app.connect("config-inited", validate_config)

    return {
        "version": __version__,
        "parallel_read_safe": True,
    }
Exemplo n.º 17
0
def truncate_class_role(name,
                        rawtext,
                        text,
                        lineno,
                        inliner,
                        options={},
                        content=[]):
    if "<" not in rawtext:
        text = "{} <{}>".format(text.split(".")[-1], text)
        rawtext = ":{}:`{}`".format(name, text)

    # Return a python x-reference
    py_xref = PyXRefRole()
    return py_xref("py:class",
                   rawtext,
                   text,
                   lineno,
                   inliner,
                   options=options,
                   content=content)
Exemplo n.º 18
0
def truncate_class_role(name,
                        rawtext,
                        text,
                        lineno,
                        inliner,
                        options={},
                        content=[]):
    if '<' not in rawtext:
        text = '{} <{}>'.format(text.split('.')[-1], text)
        rawtext = ':{}:`{}`'.format(name, text)

    # Return a python x-reference
    py_xref = PyXRefRole()
    return py_xref('py:class',
                   rawtext,
                   text,
                   lineno,
                   inliner,
                   options=options,
                   content=content)
def setup(app: Sphinx) -> SphinxExtMetadata:
	"""
	Setup :mod:`sphinx_toolbox.more_autodoc.autonamedtuple`.

	:param app: The Sphinx app.

	.. versionadded:: 0.8.0
	"""

	# Hack to get the docutils tab size, as there doesn't appear to be any other way
	app.setup_extension("sphinx_toolbox.tweaks.tabsize")

	app.registry.domains["py"].object_types["namedtuple"] = ObjType(_("namedtuple"), "namedtuple", "class", "obj")
	app.add_directive_to_domain("py", "namedtuple", PyClasslike)
	app.add_role_to_domain("py", "namedtuple", PyXRefRole())

	app.add_autodocumenter(NamedTupleDocumenter)

	add_nbsp_substitution(app.config)  # type: ignore

	return {"parallel_read_safe": True}
Exemplo n.º 20
0
def setup(app):
    app.add_autodocumenter(IndicatorDocumenter)
    app.add_directive_to_domain("py", "indicator", IndicatorDirective)
    app.add_role_to_domain("py", "indicator", PyXRefRole())
Exemplo n.º 21
0
def setup(app):
    app.add_autodocumenter(YAMLFunctionDocumenter)
    app.add_directive_to_domain("py", "yamlfunction", PyYAMLFunction)
    app.add_role_to_domain("py", "yamlfunction", PyXRefRole())