### Install sphinx-multiversion Source: https://context7.com/my-rds-store/multiversion/llms.txt Installs the sphinx-multiversion package from PyPI, GitHub, or a local clone. Requires pip for installation. ```bash # Install from PyPI pip install sphinx-multiversion # Install latest development version from GitHub pip install git+https://github.com/sphinx-contrib/multiversion.git # Install from local clone git clone https://github.com/sphinx-contrib/multiversion.git cd multiversion pip install . ``` -------------------------------- ### Build Documentation with sphinx-build vs. sphinx-multiversion Source: https://github.com/my-rds-store/multiversion/blob/main/docs/quickstart.md Compares the command-line usage of the standard sphinx-build with sphinx-multiversion, demonstrating how to build documentation for multiple versions. ```bash # Without sphinx-multiversion sphinx-build docs build/html # With sphinx-multiversion sphinx-multiversion docs build/html ``` -------------------------------- ### Install sphinx-multiversion from a local clone using pip Source: https://github.com/my-rds-store/multiversion/blob/main/docs/install.md Installs sphinx-multiversion from a local clone of its Git repository. This method involves cloning the repository, navigating into the directory, and then using pip to install. ```bash git clone https://github.com/sphinx-contrib/multiversion.git cd multiversion pip install . ``` -------------------------------- ### Add sphinx-multiversion Extension to conf.py Source: https://github.com/my-rds-store/multiversion/blob/main/docs/quickstart.md Shows how to add the 'sphinx_multiversion' extension to the Sphinx configuration file (conf.py) to enable its functionality. ```python extensions = [ "sphinx_multiversion", ] ``` -------------------------------- ### Install sphinx-multiversion from PyPI using pip Source: https://github.com/my-rds-store/multiversion/blob/main/docs/install.md Installs the latest stable release of sphinx-multiversion from the Python Package Index (PyPI) using pip. This is the recommended method for most users. ```bash pip install sphinx-multiversion ``` -------------------------------- ### Configure Sidebar for Version Picker Source: https://github.com/my-rds-store/multiversion/blob/main/docs/quickstart.md Demonstrates how to configure the Sphinx project to include the custom versioning template in the sidebar, assuming the theme supports sidebar widgets. ```python templates_path = [ "_templates", ] html_sidebars = { '**': [ 'versioning.html', ], } ``` -------------------------------- ### Setup gh-pages Branch and Build Docs (Bash) Source: https://github.com/my-rds-store/multiversion/blob/main/docs/github_pages.md This snippet demonstrates the bash commands to set up a `gh-pages` branch, disable Jekyll, build the documentation using `sphinx-multiversion`, and commit the generated HTML files to the `gh-pages` branch for deployment. ```bash git checkout --orphan gh-pages touch .nojekyll git add .nojekyll git commit -m "Disable Jekyll" mkdir html sphinx-multiversion docs/ html/ git checkout gh-pages for dirname in html/*; do mv "html/$dirname" "$dirname" && git add "$dirname"; done git commit -m "Added HTML docs" git push origin gh-pages ``` -------------------------------- ### Output Directory Format Examples Source: https://github.com/my-rds-store/multiversion/blob/main/docs/configuration.md These Python examples illustrate various formats for `smv_outputdir_format` in sphinx-multiversion. This setting controls the subdirectory structure within the Sphinx output directory for each versioned documentation build, using Python's new-style formatting. ```python smv_outputdir_format = '{ref.name}' # Use the branch/tag name smv_outputdir_format = '{ref.commit}' # Use the commit hash smv_outputdir_format = '{ref.commit:.7s}' # Use the commit hash truncated to 7 characters smv_outputdir_format = '{ref.refname}' # Use the full refname smv_outputdir_format = '{ref.source}/{ref.name}' # Equivalent to the previous example smv_outputdir_format = 'versions/{config.release}' # Use "versions" as parent directory and the "release" variable from conf.py smv_outputdir_format = '{config.version}/{ref.name}' # Use the version from conf.py as parent directory and the branch/tag name as subdirectory ``` -------------------------------- ### Release Pattern Examples Source: https://github.com/my-rds-store/multiversion/blob/main/docs/configuration.md This Python code shows examples of regular expressions used to define the `smv_released_pattern` in sphinx-multiversion. This pattern distinguishes between released and development versions of the documentation based on the Git refname. ```python smv_released_pattern = r'^refs/tags/.*$' # Tags only smv_released_pattern = r'^refs/heads/\d+\.\d+$' # Branches like "2.1" smv_released_pattern = r'^refs/(tags/.*|heads/\d+\.\d+)$' # Branches like "2.1" and all tags smv_released_pattern = r'^refs/(tags|heads|remotes/[^/]+)/(?!master).*$' # Everything except master branch ``` -------------------------------- ### Tag/Branch/Remote Whitelist Examples Source: https://github.com/my-rds-store/multiversion/blob/main/docs/configuration.md These Python examples demonstrate how to use regular expressions to define whitelists for tags, branches, and remotes in sphinx-multiversion. These whitelists determine which Git references are included when building versioned documentation. ```python smv_tag_whitelist = r'^.*$' # Include all tags smv_tag_whitelist = r'^v\d+\.\d+$' # Include tags like "v2.1" smv_branch_whitelist = r'^.*$' # Include all branches smv_branch_whitelist = r'^(?!master).*$' # Include all branches except "master" smv_remote_whitelist = None # Only use local branches smv_remote_whitelist = r'^.*$' # Use branches from all remotes smv_remote_whitelist = r'^(origin|upstream)$' # Use branches from origin and upstream ``` -------------------------------- ### Install sphinx-multiversion from GitHub using pip Source: https://github.com/my-rds-store/multiversion/blob/main/docs/install.md Installs the latest development version of sphinx-multiversion directly from its GitHub repository using pip. This is useful for testing the newest features or bug fixes. ```bash pip install git+https://github.com/sphinx-contrib/multiversion.git ``` -------------------------------- ### GitHub Actions CI/CD for Sphinx Multiversion Docs Source: https://context7.com/my-rds-store/multiversion/llms.txt Automates the building and deployment of Sphinx documentation with the sphinx-multiversion extension using a GitHub Actions workflow. It checks out code, sets up Python, installs dependencies, builds the documentation, and deploys it to GitHub Pages. ```yaml # .github/workflows/docs.yaml name: Build Documentation on: push: branches: [main] release: types: [published] jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0 # Required for git history - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.x' - name: Install dependencies run: | pip install sphinx sphinx-multiversion - name: Build docs run: | mkdir html sphinx-multiversion docs/ html/ touch html/.nojekyll cp assets/gh-pages-redirect.html html/index.html - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./html ``` -------------------------------- ### Overriding Configuration Variables Example Source: https://github.com/my-rds-store/multiversion/blob/main/docs/configuration.md This command-line example shows how to override sphinx-multiversion configuration variables using the `-D` flag. It demonstrates passing a configuration value for the 'exhale_args.containmentFolder' setting, using `${sourcedir}` as a placeholder. ```bash sphinx-multiversion docs build/html -D 'exhale_args.containmentFolder=${sourcedir}/api' ``` -------------------------------- ### Using vhasdoc() and vpathto() Functions in HTML Templates Source: https://context7.com/my-rds-store/multiversion/llms.txt This HTML snippet illustrates the usage of two helper functions: `vhasdoc(other_version)` to check if a page exists in another version, and `vpathto(other_version)` to generate a relative URL to the current page in another version. It provides examples of conditional linking and displaying page availability. ```html {% if vhasdoc('master') %}

This page is available in master.

{% else %}

This page doesn't exist in master yet.

{% endif %} {% for ver in versions.releases %} {% if vhasdoc(ver.name) %} {{ ver.name }} {% else %} {{ ver.name }} (page unavailable) {% endif %} {% endfor %} ``` -------------------------------- ### Get Path to Document in Another Version (vpathto) Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja code snippet uses the 'vpathto' function to generate a relative URL to the current page in a specified 'other_version'. It handles cases where the page might not exist in the target version by defaulting to the master document. ```jinja {% if vhasdoc('master') %} This page is also available in master. {% else %} Go to master for the latest docs. {% endif %} ``` -------------------------------- ### Automate Documentation Builds with Travis CI (YAML) Source: https://github.com/my-rds-store/multiversion/blob/main/docs/github_pages.md This YAML configuration for `.travis.yml` automates the documentation build and deployment process. It builds the documentation using `sphinx-multiversion`, adds a `.nojekyll` file, and sets up a redirect before deploying the output to the `gh-pages` branch. ```yaml script: # Build documentation - mkdir html - sphinx-multiversion docs/ html/ before_deploy: # Add .nojekyll file and redirect from docroot to the sphinx output dir - touch html/.nojekyll - cp assets/gh-pages-redirect.html html/index.html deploy: # Only deploy the sphinx output dir as gh-pages branch - provider: pages skip_cleanup: true github_token: $GITHUB_TOKEN keep_history: false local_dir: html ``` -------------------------------- ### Deploying Versioned Documentation to GitHub Pages using Bash Source: https://context7.com/my-rds-store/multiversion/llms.txt This bash script outlines the process for deploying versioned documentation to GitHub Pages. It involves creating an orphan 'gh-pages' branch, disabling Jekyll, building the documentation using 'sphinx-multiversion', and then pushing the generated HTML files to the 'gh-pages' branch. ```bash # Create orphan gh-pages branch with Jekyll disabled git checkout --orphan gh-pages touch .nojekyll git add .nojekyll git commit -m "Disable Jekyll" # Switch back to main branch and build docs git checkout main mkdir html sphinx-multiversion docs/ html/ # Deploy to gh-pages git checkout gh-pages for dirname in html/*; do mv "html/$dirname" "$dirname" && git add "$dirname" done git commit -m "Added HTML docs" git push origin gh-pages # Access at: https://username.github.io/reponame/main/ ``` -------------------------------- ### Create Version Picker Sidebar Template Source: https://context7.com/my-rds-store/multiversion/llms.txt Creates a sidebar template (`_templates/versioning.html`) for Sphinx to list all available documentation versions, enabling users to switch between them. Requires configuring `templates_path` and `html_sidebars` in `conf.py`. ```html {% if versions %}

{{ _('Versions') }}

{% endif %} ``` ```python # conf.py - Register the template templates_path = ["_templates"] html_sidebars = { '**': [ 'versioning.html', ], } ``` -------------------------------- ### Build Versioned Documentation with sphinx-multiversion Source: https://context7.com/my-rds-store/multiversion/llms.txt Builds documentation for all Git branches and tags matching specified whitelist patterns. Supports dumping metadata for debugging and overriding configuration via the command line. ```bash # Basic usage - builds all whitelisted versions sphinx-multiversion docs build/html # Dump metadata to see which refs will be built (useful for debugging) sphinx-multiversion docs build/html --dump-metadata # Override configuration on command line sphinx-multiversion docs build/html -D 'smv_tag_whitelist=^v\d+\.\d+$' # Override with placeholders for version-specific paths sphinx-multiversion docs build/html -D 'exhale_args.containmentFolder=${sourcedir}/api' ``` -------------------------------- ### HTML Root Redirect for GitHub Pages Source: https://context7.com/my-rds-store/multiversion/llms.txt Creates an index.html file at the root of the gh-pages branch to redirect users to the default version of the documentation. This is a simple HTML meta refresh redirect. ```html Redirecting to master branch ``` -------------------------------- ### Redirect to Master Branch (HTML) Source: https://github.com/my-rds-store/multiversion/blob/main/docs/github_pages.md This HTML snippet creates an `index.html` file to redirect users from the root of the GitHub Pages URL to the documentation of the 'master' branch. It uses meta refresh and a canonical link for redirection. ```html Redirecting to master branch ``` -------------------------------- ### Read the Docs Theme Version Picker HTML Template Source: https://context7.com/my-rds-store/multiversion/llms.txt This HTML template snippet is designed for the Read the Docs theme to create a version picker. It displays the current version and provides dropdowns for other versions, categorized into 'Tags' and 'Branches', with links to each version. ```html {%- if current_version %}
Other Versions v: {{ current_version.name }}
{%- if versions.tags %}
Tags
{%- for item in versions.tags %}
{{ item.name }}
{%- endfor %}
{%- endif %} {%- if versions.branches %}
Branches
{%- for item in versions.branches %}
{{ item.name }}
{%- endfor %}
{%- endif %}
{%- endif %} ``` -------------------------------- ### Configure sphinx-multiversion in conf.py Source: https://context7.com/my-rds-store/multiversion/llms.txt Configures sphinx-multiversion by defining whitelist patterns for tags, branches, and remotes, as well as output directory formats and release patterns within the Sphinx project's `conf.py` file. ```python # conf.py - Add extension extensions = [ "sphinx_multiversion", ] # Whitelist patterns for tags (regex, None to ignore all tags) smv_tag_whitelist = r'^.*$' # Include all tags smv_tag_whitelist = r'^v\d+\.\d+$' # Include tags like "v2.1" smv_tag_whitelist = r'^v\d+\.\d+\.\d+$' # Include tags like "v1.2.3" # Whitelist patterns for branches (regex, None to ignore all branches) smv_branch_whitelist = r'^.*$' # Include all branches smv_branch_whitelist = r'^(?!master).*$' # Exclude master branch smv_branch_whitelist = r'^(main|develop)$' # Only main and develop # Whitelist patterns for remotes (None = local only) smv_remote_whitelist = None # Only local branches smv_remote_whitelist = r'^.*$' # All remotes smv_remote_whitelist = r'^(origin|upstream)$' # Specific remotes # Pattern to identify released versions (matched against full refname) smv_released_pattern = r'^refs/tags/.*$' # All tags are releases smv_released_pattern = r'^refs/heads/\d+\.\d+$' # Branches like "2.1" smv_released_pattern = r'^refs/(tags|heads)/(?!master).*$' # Everything except master # Output directory format (Python format string) smv_outputdir_format = '{ref.name}' # Use branch/tag name smv_outputdir_format = '{ref.commit}' # Use commit hash smv_outputdir_format = '{ref.commit:.7s}' # Truncated commit hash smv_outputdir_format = 'versions/{config.release}' # Use release from conf.py smv_outputdir_format = '{config.version}/{ref.name}' # Nested structure # Prefer remote refs when output dirs conflict smv_prefer_remote_refs = False # Set the latest version for banners smv_latest_version = "master" ``` -------------------------------- ### Version Banner for Old or Development Documentation in HTML Source: https://context7.com/my-rds-store/multiversion/llms.txt This HTML template snippet extends a base page template to display a warning banner for users viewing old or development documentation. It checks if the current version is different from the latest version and if it's released or a development version, providing a link to the latest version. ```html {% extends "!page.html" %} {% block body %} {% if current_version and latest_version and current_version != latest_version %}

{% if current_version.is_released %} You're reading an old version of this documentation. If you want up-to-date information, please have a look at {{ latest_version.name }}. {% else %} You're reading the documentation for a development version. For the latest released version, please have a look at {{ latest_version.name }}. {% endif %}

{% endif %} {{ super() }} {% endblock %} ``` -------------------------------- ### Python Accessing Sphinx Multiversion Environment Variables Source: https://context7.com/my-rds-store/multiversion/llms.txt Demonstrates how to access environment variables set by sphinx-multiversion within the Sphinx configuration file (conf.py). These variables provide information about the current version being built, such as branch name, version string, and source/output directories. ```python # conf.py - Access environment variables set by sphinx-multiversion import os # Available environment variables during build: # SPHINX_MULTIVERSION_NAME - Branch/tag name being built # SPHINX_MULTIVERSION_VERSION - Version string from conf.py # SPHINX_MULTIVERSION_RELEASE - Release string from conf.py # SPHINX_MULTIVERSION_SOURCEDIR - Source directory path # SPHINX_MULTIVERSION_OUTPUTDIR - Output directory path # SPHINX_MULTIVERSION_CONFDIR - Configuration directory path current_version = os.environ.get('SPHINX_MULTIVERSION_NAME', 'unknown') print(f"Building documentation for: {current_version}") ``` -------------------------------- ### HTML Template: List Releases and Development Versions Separately Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This HTML template snippet categorizes version listings into 'Releases' and 'In Development'. It uses 'versions.releases' and 'versions.in_development' for iteration. ```html {% if versions %}

{{ _('Releases') }}

{{ _('In Development') }}

{% endif %} ``` -------------------------------- ### HTML Template: List All Versions Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This HTML template snippet displays a list of all available versions. It iterates through the 'versions' object and creates a link for each version. ```html {% if versions %}

{{ _('Versions') }}

{% endif %} ``` -------------------------------- ### Default sphinx-multiversion Configuration Source: https://github.com/my-rds-store/multiversion/blob/main/docs/configuration.md This Python code snippet shows the default configuration settings for sphinx-multiversion in a Sphinx conf.py file. These settings control which tags, branches, and remotes are included, how released versions are identified, and the format of output directories. ```python # Whitelist pattern for tags (set to None to ignore all tags) smv_tag_whitelist = r'^.*$' # Whitelist pattern for branches (set to None to ignore all branches) smv_branch_whitelist = r'^.*$' # Whitelist pattern for remotes (set to None to use local branches only) smv_remote_whitelist = None # Pattern for released versions smv_released_pattern = r'^tags/.*$' # Format for versioned output directories inside the build directory smv_outputdir_format = '{ref.name}' # Determines whether remote or local git branches/tags are preferred if their output dirs conflict smv_prefer_remote_refs = False ``` -------------------------------- ### Separate Branches and Tags in Version Picker Source: https://context7.com/my-rds-store/multiversion/llms.txt Customizes the version picker sidebar template to display branches and tags in separate, distinct sections. This enhances user navigation by clearly differentiating between release tags and development branches. Requires `templates_path` and `html_sidebars` configuration in `conf.py`. ```html {% if versions %}

{{ _('Branches') }}

{{ _('Tags') }}

{% endif %} ``` -------------------------------- ### HTML Template: Version Banner for Old/Development Versions Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This HTML template snippet displays a banner indicating if the user is viewing an old or development version of the documentation. It compares the current version with the latest released version and provides a link to the latest. ```html {% extends "!page.html" %} {% block body %} {% if current_version and latest_version and current_version != latest_version %}

{% if current_version.is_released %} You're reading an old version of this documentation. If you want up-to-date information, please have a look at {{latest_version.name}}. {% else %} You're reading the documentation for a development version. For the latest released version, please have a look at {{latest_version.name}}. {% endif %}

{% endif %} {{ super() }} {% endblock %}% ``` -------------------------------- ### Accessing Version Object Attributes in HTML Templates Source: https://context7.com/my-rds-store/multiversion/llms.txt This HTML snippet demonstrates how to access attributes of a 'Version' object within templates. It shows how to display version names, URLs, 'version' and 'release' values from conf.py, and a 'Released' badge if the version matches the release pattern. It also shows how to display current and latest version information. ```html {% for item in versions %}
{{ item.name }} View Version: {{ item.version }} Release: {{ item.release }} {% if item.is_released %} Released {% endif %}
{% endfor %}

Currently viewing: {{ current_version.name }} ({{ current_version.release }})

Latest version: {{ latest_version.name }}

``` -------------------------------- ### HTML Template: List Branches and Tags Separately Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This HTML template snippet separates version listings into 'Branches' and 'Tags'. It iterates through 'versions.branches' and 'versions.tags' respectively. ```html {% if versions %}

{{ _('Branches') }}

{{ _('Tags') }}

{% endif %} ``` -------------------------------- ### Iterate Through All Versions in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja template code iterates through all available 'Version' objects and displays them as a list of links. It assumes the 'versions' iterable is available in the HTML context. ```jinja

Versions

``` -------------------------------- ### Iterate Through Released Versions in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja template code iterates through 'Version' objects where 'is_released' is true, displaying them as a list of links. It relies on the 'versions.releases' property. ```jinja

Releases

``` -------------------------------- ### Iterate Through In-Development Versions in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja template code iterates through 'Version' objects where 'is_released' is false, displaying them as a list of links. It uses the 'versions.in_development' property. ```jinja

In Development

``` -------------------------------- ### Iterate Through Branch Versions in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja template code iterates through 'Version' objects specifically for branches and displays them as a list of links. It utilizes the 'versions.branches' property. ```jinja

Branches

``` -------------------------------- ### HTML Template for ReadTheDocs Theme Version Widget Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This HTML template snippet is designed for the Read the Docs theme to display a version selection widget in the sidebar. It lists available tags and branches with links. ```html {%- if current_version %}
Other Versions v: {{ current_version.name }}
{%- if versions.tags %}
Tags
{%- for item in versions.tags %}
{{ item.name }}
{%- endfor %}
{%- endif %} {%- if versions.branches %}
Branches
{%- for item in versions.branches %}
{{ item.name }}
{%- endfor %}
{%- endif %}
{%- endif %} ``` -------------------------------- ### Iterate Through Tag Versions in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja template code iterates through 'Version' objects specifically for tags and displays them as a list of links. It uses the 'versions.tags' property. ```jinja

Tags

``` -------------------------------- ### Configure Sphinx for Custom Templates Source: https://github.com/my-rds-store/multiversion/blob/main/docs/templates.md This snippet configures Sphinx to use custom templates. It specifies the path to the template directory and adds a custom template file to the HTML sidebars. ```python templates_path = [ "_templates", ] html_sidebars = [ "versioning.html", ] ``` -------------------------------- ### Display Current Version Name in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja code snippet displays the name of the currently building version using the 'current_version.name' variable, which is a 'Version' object. ```jinja

Current Version: {{ current_version.name }}

``` -------------------------------- ### Check Document Existence in Another Version (vhasdoc) Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja code snippet uses the 'vhasdoc' function to check if the current document exists in a specified 'other_version' (e.g., 'master'). It conditionally displays a link if the document is found. ```jinja {% if vhasdoc('master') %} This page is available in master. {% endif %} ``` -------------------------------- ### Display Latest Released Version Name in HTML Context Source: https://github.com/my-rds-store/multiversion/blob/main/docs/context.md This Jinja code snippet displays the name of the latest released version using the 'latest_version.name' variable, which is a 'Version' object. ```jinja

Latest Version: {{ latest_version.name }}

``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.