Skip to main content

A versions menu for Sphinx-based documentation

Project description

Docs-Versions-Menu

Source code on Github Documentation docs-versions-menu on the Python Package Index docs-versions-menu on conda-forge Docs PyPI Tests Codecov MIT License

A versions-menu for Sphinx-based documentation.

Historically, many open source projects have hosted their documentation on Read the Docs (RTD). However, RTD has a fixed build process that is essentially limited to just running Sphinx. Moreover, RTD will inject advertisements into your documentation.

A more flexible approach is to build the documentation with continuous integration (e.g., Github Actions) and to deploy the result to Github Pages or any other static site hosting. There are no restrictions on the build process: it may involve make, tox, latex, or any number of custom scripts to augment Sphinx.

The one difficulty that comes with self-hosting project documentation is that out of the box, there is no support for showing multiple releases or branches of the project. This project aims to remedy this. It provides a Sphinx extension and a command-line tool that work together to generate a dynamic versions-menu similar to that on RTD pages.

Docs-Versions-Menu Screenshot

The different “Versions” derive from the folder structure of the hosted documentation, e.g., for Github Pages, the folders in the root of the gh-pages branch. The docs-versions-menu command-line tool, running on the gh-pages branch or on the server hosting the documentation, collects the available versions based on the folders it sees.

The docs_versions_menu Sphinx extension, running during the Sphinx build process, adds Javascript to the documentation that will inject a menu to switch between the found versions. It can also show warnings for outdated or unreleased versions.

See the Docs-Versions-Menu documentation itself for a live example.

Development of Docs-Versions-Menu happens on Github. You can read the full documentation online.

Installation

To install the latest released version of docs-versions-menu, run:

pip install docs-versions-menu

Or, to install the latest development version of docs-versions-menu from Github:

pip install git+https://github.com/goerz/docs_versions_menu.git@master#egg=docs_versions_menu

The docs-versions-menu package can also be installed through conda, using the conda-forge channel. See the instructions in the Docs-Versions-Menu Feedstock.

Usage

Showing a versions-menu in your documentation requires two steps:

  1. Add 'docs_versions_menu' to the list of extensions in your Sphinx conf.py.

    This adds Javascript to your rendered documentation that displays a dynamic versions-menu based on information in a versions.json file it expects to find in the webroot of the hosted documentation, e.g. the root of the gh-pages branch.

  2. Set up the deployment of the documentation such that it runs the docs-versions-menu command in the webroot.

    The command creates the file versions.json that step 1 depends on by analyzing the folders it finds in the webroot.

    How to invoke docs-versions-menu depends on the specifics of how the documentation is deployed:

    • For Github Actions deploying to Github Pages, check out the gh-pages branch, run docs-versions-menu, and commit and push the resulting files. See the workflow file for Docs-Versions-Menu’s documentation.

    • For Travis deploying to Github Pages with Doctr, tell doctr deploy to invoke the docs-versions-menu command:

      doctr deploy --command=docs-versions-menu --no-require-master --build-tags "$DEPLOY_DIR"
    • For deployments to a static web host, use ssh to run the docs-versions-menu command on the server

See the full documentation on Step 1 and Step 2 for details.

Default assumptions

For projects that follow standard best practices, you should not require any customization beyond the above two steps.

  • Releases should be tagged as e.g. v0.1.0 and deployed to a folder of the same name. That is, a lower case letter v followed by a PEP 440-compatible version identifier.

  • The master branch should be deployed to a folder master, respectively main to a folder main for projects that use “main” as the default branch name.

  • Any other branch for which documentation is to be deployed should go in a folder matching the branch name.

Examples

The following projects use Docs-Versions-Menu, respectively its predecessor Doctr-Versions-Menu:

History

0.5.2 (2023-04-19)

  • Compatibility with packaging >= 22.0 (#27, #32)

0.5.1 (2023-01-25)

  • Pin packaging dependency to < 22.0 (#27, #28)

0.5.0 (2022-11-17)

  • Renamed project to docs-versions-menu (#13)

  • Changed: Removed support for a config file (#9)

  • Dropped support for Python 3.5 and Python 3.6

  • Added support for Python 3.10 and 3.11

  • Improvements to the workflow and documentation.

  • Update of conda-feedstock

Migration from doctr-versions-menu

The doctr-versions-menu package was renamed to docs-versions-menu to reflect that Travis and thus Doctr is no longer a viable option to deploy documentation. Switching from doctr-versions-menu to docs-versions-menu requires the following steps:

  • Consider switching from Travis to Github Actions

  • Update your Sphinx configuration (conf.py):
    • Rename the doctr_versions_menu_conf dictionary of settings to docs_versions_menu_conf.

    • Change the name of the doctr_versions_menu extension in the extensions list to docs_versions_menu.

    • If using a custom doctr-versions-menu.js_t template, rename the file to docs-versions-menu.js_t

  • Update your continuous-integration setup:
    • Replace the doctr-versions-menu package with docs-versions-menu in the project requirements (setup.py/setup.cfg)

    • Replace the installation of the doctr-versions-menu package with docs-versions-menu in your CI script or environment files

    • Replace calls to the doctr-versions-menu executable with calls to docs-versions-menu

    • If using environment variables for configuration, change the DOCTR_VERSIONS_MENU prefix to DOCS_VERSIONS_MENU

  • For any project using a doctr-versions-menu.conf file in the gh-pages root, set up equivalent DOCS_VERSIONS_MENU_* environment variables

To ease migration, the new docs-versions-menu will still process doctr_versions_menu_conf, DOCTR_VERSIONS_MENU environment variables, and a doctr-versions-menu.js_t template, while emitting a warning. This limited backwards-compatibility may be removed in later versions.

0.4.1 (2021-03-18)

Note: this release was under the project name doctr-versions-menu.

  • Fixed: The doctr-versions-menu exectuable no longer fails when run outside of a git repository (#15, thanks to Alexander Blech)

  • Fixed: Custom doctr-versions-menu.js_t template were being ignored (#18)

0.4.0 (2020-12-14)

Note: this release was under the project name doctr-versions-menu.

  • Added: The label in the top left corner of the version menu can now be configured in conf.py (setting menu_title).

  • Added: --default-branch option, <default-branch> group for folder specifications, and default-branch field in versions.json (#12)

  • Changed: The default --versions now uses <default-branch>, automatically picking up on either “master” or “main” as the default branch (#12)

  • Changed: The default template for index.html now automatically forwards to the default-branch (based on the --default-branch option, instead of just “master”), or the first available branch if there is no released version (#12)

This release addresses two major compatibility issues:

  1. Both git and Github have recently switched the name of the default branch from “master” to “main”. This release adds support for new projects using “main” as their default branch.

  2. As of December 2020, Travis CI has stopped their support for open source. Consequently, Doctr can no longer be used to deploy documentation at no cost. This release adds rudimentary support for deploying the documenation with Github Actions instead of Doctr, see Deployment with Github Actions.

0.3.0 (2020-08-03)

Note: this release was under the project name doctr-versions-menu.

  • Added: --no-downloads-file option, downloads_file = False in config. (#4, thanks to Tyler Pennebaker)

  • Fixed: versions.py on gh-pages branch was not being committed (#5)

  • Fixed: Compatibility with any pyparsing version >= 2.0.2 (#8, thanks to Hugo Slepicka)

  • Added: The doctr-versions-menu executable can now be configured through environment variables. This allows to keep configuration on the source branch, in the .travis.yml file (#6, thanks to Tyler Pennebaker)

  • The Doctr Versions Menu package can now be installed via conda (thanks to Hugo Slepicka)

0.2.0 (2020-03-14)

Note: this release was under the project name doctr-versions-menu.

  • Added: --versions option for customizing which folders appear in the versions menu and in which order.

  • Added: --label option for customizing the labels appearing the versions menu

  • Added: --warning option for customizing on which folders specific warnings are displayed

  • Added: --latest option for configuring which folder is the “latest stable release”

  • Added: Write a script versions.py to the root of the gh-pages branch (--write-versions-py option)

  • Changed: unreleased and pre-released versions now show different warnings by default

  • Changed: index.html template is now rendered with full version_data

  • Changed: development/pre-release versions now longer have the “dev” suffix in the versions menu by default

  • Changed: The versions menu now uses the same ordering of versions as Read-the-Docs, by default: the folders are ordered from most current to least current.

  • Changed: internal format of versions.json

  • Removed: --default-branch option. This is replaced by the new --latest option and enhanced template rendering of the index.html

  • Removed: --suffix-unreleased option. This can now be achieved via the --label option

This is a major release that breaks backwards compatibility.

Specifically, due to the changes in versions.json, when upgrading from older versions, it may be necessary to replace doctr-versions-menu.js files in existing folders in a project’s gh-pages branch.

0.1.0 (2020-01-11)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docs_versions_menu-0.5.2.tar.gz (782.9 kB view details)

Uploaded Source

Built Distribution

docs_versions_menu-0.5.2-py3-none-any.whl (533.2 kB view details)

Uploaded Python 3

File details

Details for the file docs_versions_menu-0.5.2.tar.gz.

File metadata

  • Download URL: docs_versions_menu-0.5.2.tar.gz
  • Upload date:
  • Size: 782.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for docs_versions_menu-0.5.2.tar.gz
Algorithm Hash digest
SHA256 8c6eae5836fb63e4f9700387385c5074dac8187609538422dab5fa39de110a73
MD5 48d8f3649d5d40478ae0e37fb4251855
BLAKE2b-256 9eb733bb6d00593ce0a7df5d4b13871b798d1cc8fd798933f036b058568dbe2d

See more details on using hashes here.

File details

Details for the file docs_versions_menu-0.5.2-py3-none-any.whl.

File metadata

File hashes

Hashes for docs_versions_menu-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e331e2e9b2c9d3a7b2a7c8325a7e7ed7070b144cd3ef0f701172468af7e3cdf
MD5 6e6217ae247160230108b593b9c922c1
BLAKE2b-256 232389993b2e9895add5e76a3f38ceb3c06dc2f1d0733937568085a36a56b21b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page