Exemplo n.º 1
0
def validate_config(app: Sphinx, config: ToolboxConfig):
    r"""
	Validate the provided configuration values.


	See :class:`~sphinx_toolbox.config.ToolboxConfig` for a list of the configuration values.

	:param app: The Sphinx app.
	:param config:
	:type config: :class:`~sphinx.config.Config`
	"""

    config.source_link_target = str(config.source_link_target).lower().strip()

    if config.source_link_target not in {"sphinx", "github"}:
        raise InvalidOptionError("Invalid value for 'source_link_target'.")

    if not config.github_username:
        raise MissingOptionError("The 'github_username' option is required.")
    else:
        config.github_username = str(config.github_username)

    if not config.github_repository:
        raise MissingOptionError("The 'github_repository' option is required.")
    else:
        config.github_repository = str(config.github_repository)

    config.github_url = make_github_url(config.github_username,
                                        config.github_repository)
    config.github_source_url = config.github_url / "blob" / "master"
    config.github_issues_url = config.github_url / "issues"
    config.github_pull_url = config.github_url / "pull"

    add_nbsp_substitution(config)
Exemplo n.º 2
0
 def __init__(self,
              directive: DocumenterBridge,
              name: str,
              indent: str = '') -> None:
     super().__init__(directive=directive, name=name, indent=indent)
     self.options = Options(self.options.copy())
     add_nbsp_substitution(self.env.app.config)
Exemplo n.º 3
0
def configure(app: Sphinx, config: Config):
    """
	Configure :mod:`sphinx_toolbox.code`.

	.. versionadded:: 2.11.0

	:param app: The Sphinx application.
	:param config:
	"""

    latex_elements = getattr(app.config, "latex_elements", {})

    latex_preamble = StringList(latex_elements.get("preamble", ''))
    latex_preamble.blankline()
    latex_preamble.append(r"\definecolor{regex_literal}{HTML}{696969}")
    latex_preamble.append(r"\definecolor{regex_at}{HTML}{FF4500}")
    latex_preamble.append(r"\definecolor{regex_repeat_brace}{HTML}{FF4500}")
    latex_preamble.append(r"\definecolor{regex_branch}{HTML}{FF4500}")
    latex_preamble.append(r"\definecolor{regex_subpattern}{HTML}{1e90ff}")
    latex_preamble.append(r"\definecolor{regex_in}{HTML}{ff8c00}")
    latex_preamble.append(r"\definecolor{regex_category}{HTML}{8fbc8f}")
    latex_preamble.append(r"\definecolor{regex_repeat}{HTML}{FF4500}")
    latex_preamble.append(r"\definecolor{regex_any}{HTML}{FF4500}")

    latex_elements["preamble"] = str(latex_preamble)
    app.config.latex_elements = latex_elements  # type: ignore
    add_nbsp_substitution(config)
Exemplo n.º 4
0
def setup(app: Sphinx) -> SphinxExtMetadata:
    """
	Setup :mod:`sphinx_toolbox.more_autodoc.variables`.

	:param app: The Sphinx app.
	"""

    app.setup_extension("sphinx.ext.autodoc")
    app.add_autodocumenter(VariableDocumenter)
    app.add_autodocumenter(TypedAttributeDocumenter, override=True)
    app.add_autodocumenter(InstanceAttributeDocumenter, override=True)
    app.add_autodocumenter(SlotsAttributeDocumenter, override=True)

    add_nbsp_substitution(app.config)  # type: ignore

    return {"parallel_read_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}
Exemplo n.º 6
0
def validate_config(app: Sphinx, config: ToolboxConfig):
    """
	Validate the provided configuration values.

	See :class:`~sphinx_toolbox.config.ToolboxConfig` for a list of the configuration values.

	:param app: The Sphinx application.
	:param config:
	:type config: :class:`~sphinx.config.Config`
	"""

    # this package
    from sphinx_toolbox import github, source

    source._configure(app, config)
    github.validate_config(app, config)
    add_nbsp_substitution(config)
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.º 8
0
def setup(app: Sphinx) -> SphinxExtMetadata:
    """
	Setup :mod:`sphinx_toolbox.more_autodoc.variables`.

	:param app: The Sphinx application.
	"""

    app.setup_extension("sphinx.ext.autodoc")
    app.setup_extension("sphinx_toolbox.more_autosummary")

    app.add_autodocumenter(VariableDocumenter)
    app.add_autodocumenter(TypedAttributeDocumenter, override=True)
    app.add_autodocumenter(InstanceAttributeDocumenter, override=True)
    app.add_autodocumenter(SlotsAttributeDocumenter, override=True)

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

    return {"parallel_read_safe": True}