API documentation
Entry application
The entry point for the package sphinx-versioned-docs is through sphinx_versioned.__main__.main().
The function is actually a Typer CLI with the various command-line options available.
- sphinx_versioned.__main__.main(chdir: str = <typer.models.OptionInfo object>, output_dir: str = <typer.models.OptionInfo object>, git_root: str = <typer.models.OptionInfo object>, local_conf: str = <typer.models.OptionInfo object>, reset_intersphinx_mapping: bool = <typer.models.OptionInfo object>, sphinx_compatibility: bool = <typer.models.OptionInfo object>, prebuild: bool = <typer.models.OptionInfo object>, branches: str = <typer.models.OptionInfo object>, main_branch: str = <typer.models.OptionInfo object>, floating_badge: bool = <typer.models.OptionInfo object>, quite: bool = <typer.models.OptionInfo object>, verbose: bool = <typer.models.OptionInfo object>, loglevel: str = <typer.models.OptionInfo object>, force_branches: bool = <typer.models.OptionInfo object>) None[source]
Typer application for initializing the
sphinx-versionedbuild.- Parameters:
chdir (
str) – Make this the current working directory before running. [Default = None]output_dir (
str) – Output directory. [Default = ‘docs/_build’]git_root (
str) – Path to directory in the local repo. Default is CWD.local_conf (
str) – Path to conf.py for sphinx-versions to read config from.reset_intersphinx_mapping (
bool) – Reset intersphinx mapping; acts as a patch for issue #17sphinx_compatibility (
bool) – Adds compatibility for older sphinx versions by monkey patching certain functions.prebuild (
bool) – Pre-builds the documentations; Use –no-prebuild to half the runtime. [Default = True]branches (
str) – Build docs for specific branches and tags. [Default = None]main_branch (
str) – Main branch to which the top-level index.html redirects to. [Default = ‘main’]floating_badge (
bool) – Turns the version selector menu into a floating badge. [Default = False]quite (
bool) – Quite output from sphinx. Use –no-quite to get output from sphinx. [Default = True]verbose (
bool) – Passed directly to sphinx. Specify more than once for more logging in sphinx. [Default = False]loglevel (
str) – Provide logging level. Example –log debug, [Default=’info’]force_branches (
str) – Force branch selection. Use this option to build detached head/commits. [Default = False]
- Return type:
Building workflow
- class sphinx_versioned.build.VersionedDocs(config: dict, debug: bool = False)[source]
Bases:
objectHandles main build workflow.
Chronologically, the
__init__()first parses the config (input parameters via adict) and then handles various paths, like current workding directory, source directory and output directory. Further, it selects the branches to pre-build/build then finally generates the top-levelindex.htmlfile.- Parameters:
config (
dict)
- _build(tag, _prebuild: bool = False) bool[source]
Internal build method which actually carries out the pre-build/build transctions inside a temporary directory then copy the asset files to the output directory if it’s not a pre-build.
- _generate_top_level_index() None[source]
Generate a top-level
index.htmlwhich redirects to the main-branch version specified viamain_branch.
- _handle_paths() None[source]
Method to handle cwd and path for local config, as well as, configure
GitVersionsand the output directory.
- build() None[source]
Build workflow.
Method to build the branch in a temporary directory with the modified
sphinx_versioned.lib.ConfigInjectand injectes the versions flyout menu to the footer or the sidebars.The method carries out the transaction via the internal build method
_build().
- prebuild() None[source]
Pre-build workflow.
Method to pre-build the selected/all branches in a temporary environment. Essentially, it builds the various selected/all branches with the vanilla sphinx-build method and pass-on the branches which ends up successful in vanilla sphinx-build.
The method carries out the transaction via the internal build method
_build().
Sphinx extension
The sphinx-extension is added by default on running sphinx-versioned to inject the versions flyout
menu directly to the html files.
Interface with Sphinx.
- class sphinx_versioned.sphinx_.EventHandlers[source]
Bases:
objectHolds Sphinx event handlers as static or class methods.
- Parameters:
CURRENT_VERSION (
str) – Current version being built.VERSIONS (
sphinx_versioned.versions.BuiltVersions) – Pass through versions for them to be linked to be linked in the badge.ASSETS_TO_COPY (
list) – Assest to copy to output directory.RESET_INTERSPHINX_MAPPING (
bool) – Reset intersphinx mapping after each build.FLYOUT_FLOATING_BADGE (
bool) – Turns the version selector menu into a floating badge.
- classmethod builder_finished_tasks(app, exc) None[source]
Method to execute tasks after the sphinx builder is finished.
- Parameters:
app (
sphinx.application.Sphinx) – Sphinx application object.exc (
Exception) – Exception.
- classmethod builder_inited(app) None[source]
Update the Sphinx builder.
- Parameters:
app (
sphinx.application.Sphinx) – Sphinx application object.
- classmethod html_page_context(app, pagename, templatename, context, doctree) None[source]
Update the Jinja2 HTML context, exposes the Versions class instance to it.
- Parameters:
app (
sphinx.application.Sphinx) – Sphinx application object.pagename (
str) – Name of the page being rendered (without .html or any file extension).templatename (
str) – Page name with .html.context (
dict) – Jinja2 HTML context.doctree (
docutils.nodes.document) – Tree of docutils nodes.
- sphinx_versioned.sphinx_.setup(app) dict[source]
Called by Sphinx during phase 0 (initialization).
- Parameters:
app (
sphinx.application.Sphinx) – Sphinx application object.- Returns:
extension version
- Return type:
Utiliies/ Libraries
- class sphinx_versioned.versions.BuiltVersions(versions: list, build_directory: str)[source]
Bases:
_BranchTagHandles versions to build. Builds upon the abstract base class
sphinx_versioned.versions._BranchTag.- Parameters:
- _parse() bool[source]
Parse raw branches/tags in
GitVersionsinstance into separate variables.
- class sphinx_versioned.versions.GitVersions(git_root: str, build_directory: str, force_branches: bool)[source]
Bases:
_BranchTagHandles git branches and tags. Builds upon the abstract base class
sphinx_versioned.versions._BranchTag.Initlizes and latches into the git repo.
- Parameters:
- _parse_branches() bool[source]
Parse branches and tags into separate variables.
Collect all branches and tags in GitVersions.all_versions. Additionally, if the head is detached and –force is supplied, then append a PseudoBranch representing the detached commit sha.
- Return type:
- property active_branch
Property to get the currently active branch.
- class sphinx_versioned.versions.PseudoBranch(name: str)[source]
Bases:
objectClass to generate a branch/pseudo-branch for git detached head/commit.
- Parameters:
name (
str) – Branch/pseudo-branch name.
- class sphinx_versioned.versions._BranchTag[source]
Bases:
ABCAbstract base class for getting relative paths of branches and tags as properties.
Common objects used throughout the project.
- class sphinx_versioned.lib.ConfigInject(*args)[source]
Bases:
ConfigInject this extension into self.extensions. Append after user’s extensions.
- class sphinx_versioned.lib.TempDir(defer_atexit=False)[source]
Bases:
objectSimilar to TemporaryDirectory in Python 3.x but with tuned weakref implementation.
- Parameters:
defer_atexit (
bool) – cleanup() to atexit instead of after garbage collection.
- sphinx_versioned.lib.mp_sphinx_compatibility() bool[source]
Monkeypatches
sphinx.application.Sphinx.add_stylesheet()->sphinx.application.Sphinx.add_css_file()to add compatibility for versions using older sphinx