click_extra.sphinx package

        classDiagram
  StatelessDomain <|-- ClickDomain
  StatelessDomain <|-- PythonDomain
    

Helpers and utilities for Sphinx.

Note

The MkDocs counterpart lives in click_extra.mkdocs, which achieves the same ANSI color rendering by patching pymdownx.highlight’s formatter classes.

Todo

Split the documentation stack into a standalone extra-docs project, should it keep growing away from the CLI framework hosting it. It would take this package, click_extra.pygments, click_extra.mkdocs, the click_extra.markdown package with its MyST converters and marker-region primitives, and the ones repomatic keeps in its own docs/docs_update.py. The open question is the click:source and click:run directives: they invoke a Click CLI, so either they stay here, or extra-docs depends on click-extra.

click_extra.sphinx.EXEC_DIRECTIVES_OPT_IN = 'click_extra_enable_exec_directives'

Name of the conf.py config flag that gates every code-execution directive.

Default is False. A project that adds click_extra.sphinx to its extensions list gets the ANSI Pygments formatter unconditionally, but does not gain access to either the click:* or the python:* directive families until the maintainer opts in explicitly. Both families exec user-supplied Python at build time with full Sphinx-process privileges: gating them behind a single explicit flag keeps a transitive import or a doc-only pull request from silently expanding the build’s attack surface.

click_extra.sphinx.setup(app)[source]

Register extensions to Sphinx.

Always-on features (no execution surface):

  • The ANSI-capable HTML formatter for Pygments (replaces sphinx.highlighting.PygmentsBridge with one that renders ANSI colors in code blocks).

  • The matrix directive, which renders a package’s compatibility grid ({matrix} python or {matrix} <distribution>) from its git tag history. It runs a canned generator rather than user-supplied Python, so it carries no execution surface and needs no opt-in. See click_extra.sphinx.matrix.

  • Deduplication of the todolist page, which sphinx.ext.todo fills with one entry per rendering of a :todo: directive rather than one per directive. Inert on a project that enables neither the extension nor a todolist, and switched off with click_extra.sphinx.todos.DEDUPE_TODOS_CONFIG. See click_extra.sphinx.todos.

  • A click_extra.sphinx.todos.UNRENDERED_TODO_WARNING warning for each :todo: in a docstring that no page renders, which no todolist can list. Inert on a project that does not enable sphinx.ext.todo, and silenced through suppress_warnings. See click_extra.sphinx.todos.

  • The todolist entries in the order of their pages, which a parallel read otherwise shuffles, and with links that reach their targets after a serial read. Inert on a project that does not enable sphinx.ext.todo. See click_extra.sphinx.todos.

  • A one-line first column for every table whose top-left cell names both axes, like the matrix tables: a narrow screen scrolls the table instead of wrapping its labels. See click_extra.sphinx.tables.

  • A crosshair on the same tables, which highlights the row and the column under the pointer, and makes a cell holding a single link clickable over its whole area. See click_extra.sphinx.crosshair.

  • A vertical layout for a sphinx-design tab-set marked with :class: tabs-vertical: its labels stack down a left rail. Deprecated for the :orientation: vertical option of sphinx-design 0.8.0, with a warning on each tab-set that carries the class. Inert without sphinx-design. See click_extra.sphinx.tabs.

  • Class diagrams of autoclasstree that let the mouse wheel scroll the page, where the d3 zoom of sphinxcontrib-mermaid would catch it. Inert without sphinxcontrib-mermaid, or with mermaid_d3_zoom off. See click_extra.sphinx.mermaid.

  • The linkcheck requests to github.com signed with the token of GITHUB_TOKEN, release downloads excepted. Inert until the variable is set. See click_extra.sphinx.linkcheck.

  • No sphinx.ext.viewcode page for a module that no documented object links to, so a parallel read publishes the pages of a serial one, and no index link to a module whose source viewcode could not read. Inert without sphinx.ext.viewcode. See click_extra.sphinx.viewcode.

  • Each [docs] link of a sphinx.ext.viewcode page pointed at the anchor of its object, where a documented instance can lend the page the module path of another module. Inert without sphinx.ext.viewcode. See click_extra.sphinx.viewcode.

  • The Python objects of a parallel read indexed as a serial read indexes them: the alias of an object that a re-exporting page declares never replaces its definition. Inert in a serial read. See click_extra.sphinx.parallel.

  • The same autodoc members on a page, whatever the pages read before it: the names that only the source of a module annotates, in an if TYPE_CHECKING: block or as self.x: T in a method. Inert without sphinx.ext.autodoc. See click_extra.sphinx.parallel.

  • A click_extra.sphinx.internal_links.DEAD_LINK_WARNING warning for each internal link of the built HTML that leads to no page, or to no anchor of its page, once per page. Inert with a builder that writes no HTML, and silenced through suppress_warnings. See click_extra.sphinx.internal_links.

  • An og:title without the space a leading title icon leaves. Inert without sphinxext-opengraph. See click_extra.sphinx.opengraph.

  • Every node of a page pointed at the page’s own document before Sphinx pickles it, which keeps the build environment out of the doctree of a page with an {eval-rst} block. See click_extra.sphinx.doctrees.

  • Changelog releases anchored on their version, like #v1-4-2, in place of a positional #idN. Inert until a project sets click_extra.sphinx.changelog.RELEASE_ANCHORS_CONFIG. See click_extra.sphinx.changelog.

  • The man-page hook, which writes roff man pages for the CLIs a project lists in click_extra.sphinx.manpages.MANPAGES_CONFIG_KEY on every HTML build. Inert until a project lists one. See click_extra.sphinx.manpages.

  • A failed build on the warning types a project lists in click_extra.sphinx.fail_on_warnings.FAIL_ON_WARNINGS_CONFIG, where Sphinx can only fail on every warning at once. Inert until a project lists one. See click_extra.sphinx.fail_on_warnings.

Opt-in features (gated behind click_extra_enable_exec_directives):

  • click:source / click:run to define and execute Click CLIs at build time.

  • click:tree / click:config to render the command reference and the configuration reference of a Click CLI at build time.

  • python:source / python:run to execute arbitrary Python at build time and render its source or captured stdout.

  • python:render / python:render-myst / python:render-rst to execute arbitrary Python and parse the captured stdout as live document content.

All directives in the opt-in group execute user-supplied Python with the same privileges as the Sphinx process. They are therefore disabled by default. Set click_extra_enable_exec_directives = True in conf.py to register them.

Caution

This function replaces the HTML formatter of sphinx.highlighting.PygmentsBridge with AnsiHtmlFormatter, for every Sphinx app of the process, so that code blocks render ANSI colors.

Return type:

ExtensionMetadata

Submodules