From: Fabrice Bauzac Date: Sun, 28 Feb 2021 17:28:45 +0100 Subject: doc generation: do not require a prior installation Forwarded: not-needed Last-Update: 2021-02-28 The build of the Sphinx documentation needs to know the version of the software. The upstream package solves this issue by requiring several steps: the Python library is built and installed, then the version is extracted from the installed library and used for building the documentation. This patch changes the process by extracting the version directly from debian/changelog, so that the build of the documentation can be done without prior installation of the package. --- docs/conf.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index f7e3bbb..7dcd272 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,7 @@ import sys import os import pkg_resources +import re # 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 @@ -63,17 +64,15 @@ author = u'Szczepan Faber, Serhiy Oplakanets, herr.kaste' # The full version, including alpha/beta/rc tags. # release = u'0.6.1' -try: - release = pkg_resources.get_distribution('mockito').version -except pkg_resources.DistributionNotFound: - print('mockito must be installed to build the documentation.') - print('Install from source using `pip install -e .` in a virtualenv.') - sys.exit(1) +# Extract the version from debian/changelog. +with open("../debian/changelog") as istream: + first_line = istream.readline() + m = re.search(r"\(([0-9.]+)", first_line) + if m: + version = '.'.join(m.group(1).split('.')[:2]) + else: + sys.exit("could not parse first changelog line: " + first_line) -if 'dev' in release: - release = ''.join(release.partition('dev')[:2]) - -version = '.'.join(release.split('.')[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages.