### 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 %}{% 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 %}{% 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 %}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 %}