Skip to content

Commit

Permalink
Fix version detection for Read the Docs documentation builds
Browse files Browse the repository at this point in the history
  • Loading branch information
sbraz committed Apr 29, 2020
1 parent 63a2e1d commit 13611f3
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import os
import subprocess

import pkg_resources

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -51,15 +53,22 @@
copyright = 'Patrick Altman, Louis Sautier'
author = 'Patrick Altman, Louis Sautier'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
# The project root is the parent directory
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Get the version from setup.py --version (inspired by jaraco.packaging)
version = subprocess.check_output([sys.executable, "setup.py", "--version"], cwd=root, universal_newlines=True).strip()
# We can't use setuptools_scm's version on Read the Docs because they alter
# conf.py before running Sphinx, dirtying the repository, which results in
# an incorrect version being computed.
# https://github.com/pypa/setuptools_scm/issues/84
# https://github.com/readthedocs/readthedocs.org/issues/2144
# Instead, follow setuptools_scm's recommendation and rely on the
# version of the installed package (which is correct because
# the repository hasn't been changed prior to installation).
# https://github.com/pypa/setuptools_scm#usage-from-sphinx
if os.environ.get("READTHEDOCS") == "True":
version = pkg_resources.get_distribution(project).version
else:
# The project root is the parent directory
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Get the version from setup.py --version (inspired by jaraco.packaging)
version = subprocess.check_output([sys.executable, "setup.py", "--version"], cwd=root, universal_newlines=True).strip()
# The full version, including alpha/beta/rc tags.
release = version

Expand Down

0 comments on commit 13611f3

Please sign in to comment.