click_extra.sphinx.manpages module¶
Sphinx integration to render roff man pages alongside the HTML build.
A project that adds click_extra.sphinx to its extensions list and
declares one or more entries in click_extra_manpages gets its Click
command tree(s) emitted as .1 files into <outdir>/<output_dir>/ on
every HTML build, with no project-local helper script. Pages mirror what
click_extra.command_doc.write_manpages() produces from a CLI invocation,
so the docs site, the release pipeline, and downstream packagers all share
one generator.
When mandoc or groff is available on PATH, each .1 file is
also rendered to a browser-viewable .html sibling. Browsers download
raw .1 files rather than display them, so the HTML pass is what makes
Sphinx’s :manpage: role useful when manpages_url points at this
hook’s output.
The hook only fires for HTML-class builders (html, dirhtml,
singlehtml). Non-HTML builders (linkcheck, man, epub,
coverage, etc.) skip it: they typically have different output
semantics, and writing roff into a linkcheck output/ directory
serves no purpose.
Configuration shape:
click_extra_manpages = [
{
"script": "meta_package_manager.cli:mpm", # required
"prog_name": "mpm", # optional, see below
"output_dir": "man", # optional, defaults to "man"
"render_html": True, # optional, see below
},
]
scriptis resolved byclick_extra.cli_wrapper.resolve_target_command()exactly as it would be from theclick-extra manCLI: aconsole_scriptsentry-point name, amodule:functionpath, a.pyfile, or a plain module name.prog_nameis the basename used for both the man-page.THheader and the generated filenames. When omitted, it falls back to the resolved Click command’s ownnameattribute (mpmfor themeta_package_manager.cli:mpmtarget), matching the default theclick-extra man --output-dirCLI uses.output_diris a relative path underapp.outdir. It is created on demand and reused across builds.render_htmltoggles the HTML sibling pass. Defaults toTrue. When no renderer is onPATH, the build still produces the.1files and logs a single info-level notice; setrender_htmltoFalseto suppress that notice.
An empty (or absent) click_extra_manpages list disables the feature,
which is the default for every project pulling in the extension.
Cross-referencing the generated pages from prose¶
To make :manpage:`myprog(1)` resolve to the HTML sibling this hook
emits, set Sphinx’s manpages_url to the same output_dir:
manpages_url = "man/{page}.{section}.html"
Sphinx’s role provides {page}, {section} and {path}
placeholders; the file layout produced here is {page}.{section} plus
the optional .html extension, so the template above matches every
file regardless of how deep the subcommand tree goes.
- click_extra.sphinx.manpages.MANPAGES_CONFIG_KEY = 'click_extra_manpages'¶
Name of the
conf.pyconfig flag holding the man-page emit list.
- click_extra.sphinx.manpages.DEFAULT_OUTPUT_DIR = 'man'¶
Subdirectory under
app.outdirwhere.1files land when the caller omits theoutput_direntry. Picked to match the URL fragment projects typically publish their man pages under (likehttps://example.com/<project>/man/<cli>.1).
- click_extra.sphinx.manpages.HTML_BUILDER_NAMES = frozenset({'dirhtml', 'html', 'singlehtml'})¶
Builder names that get the man-page emit hook.
Restricted to HTML-family builders because they are the ones whose output directory becomes the published docs site. Other builders (
linkcheck,man,epub,coverage) have different output semantics, and writing roff into their build trees would either be redundant or confusing.
- click_extra.sphinx.manpages.MANPAGE_LIST_DIRECTIVE = 'click-extra-manpages'¶
Name of the directive that renders an auto-generated index of every man page declared in
MANPAGES_CONFIG_KEY. The hyphenated form mirrors theclick_extra_manpagesconfig key it surfaces.
- class click_extra.sphinx.manpages.ManpageListDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
SphinxDirectiveRender a bullet list with one link per emitted man page.
The directive walks every entry in
MANPAGES_CONFIG_KEYand, for each, callsiter_command_contexts()to discover the (sub)command tree. Each list item links to the corresponding.1.htmlfile written by the emit hook.Link targets are stamped as build-root-relative URIs and rebased against the enclosing page by
_rebase_manpage_links, so the list works whether it appears at the docs root or in a nested page. The directive takes no arguments and no content: it surfaces whatever the config declares at the time the doc is built.- has_content = False¶
May the directive have content?
- required_arguments = 0¶
Number of required directive arguments.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- click_extra.sphinx.manpages.setup(app)[source]¶
Register the man-page hooks and the index directive on
app.Called from
click_extra.sphinx.setup()so projects only need to list"click_extra.sphinx"in theirextensions. The hooks are a no-op whenclick_extra_manpagesis unset or empty, and the directive renders nothing in that case.- Return type: