]> git.cworth.org Git - notmuch/commitdiff
doc: replace use of environment variables with a generated config
authorDavid Bremner <david@tethera.net>
Sat, 11 Jul 2020 13:20:26 +0000 (10:20 -0300)
committerDavid Bremner <david@tethera.net>
Wed, 15 Jul 2020 11:32:15 +0000 (08:32 -0300)
It is getting unwieldy to pass configuration options on the
sphinx-build command line, and I anticipate further use of
conditionals.

As far as I could tell, execing a string is the idiomatic way to
emulate include in Python.

configure
doc/Makefile.local
doc/conf.py

index 4e16ff407e6a8803c94f1601345b117b18f20afd..c8690d3a647b3da7d832c82935dadda56ff4828a 100755 (executable)
--- a/configure
+++ b/configure
@@ -1548,6 +1548,14 @@ NOTMUCH_HAVE_PYTHON3_PYTEST=${have_python3_pytest}
 PLATFORM=${platform}
 EOF
 
+cat > sphinx.config <<EOF
+# Generated by configure, run from doc/conf.py
+EOF
+if [ $WITH_EMACS = "1" ]; then
+    printf "tags.add('WITH_EMACS')\n" >> sphinx.config
+fi
+printf "rsti_dir = '%s'\n" $(realpath emacs) >> sphinx.config
+
 # Finally, after everything configured, inform the user how to continue.
 cat <<EOF
 
index 19b953ed22b8695f982f0e13fff5c344de045735..3041134101a33dd8f501340363a864a27167fbb1 100644 (file)
@@ -4,7 +4,7 @@ dir := doc
 
 # You can set these variables from the command line.
 SPHINXOPTS    := -q
-SPHINXBUILD   = WITH_EMACS=${WITH_EMACS} RSTI_DIR=$(realpath emacs) sphinx-build
+SPHINXBUILD   = sphinx-build
 DOCBUILDDIR      := $(dir)/_build
 
 # Internal variables.
index 70987ac5cc88f7030bb47548a768f807e0a491fb..fdff2a2c8ac524bacb86bb346ad03dfc2f31d997 100644 (file)
@@ -22,6 +22,13 @@ for pathdir in ['.', '..']:
         with open(version_file,'r') as infile:
             version=infile.read().replace('\n','')
 
+# read generated config
+for pathdir in ['.', '..']:
+    conf_file = os.path.join(location,pathdir,'sphinx.config')
+    if os.path.exists(conf_file):
+        with open(conf_file,'r') as infile:
+            exec(''.join(infile.readlines()))
+
 # The full version, including alpha/beta/rc tags.
 release = version
 
@@ -29,12 +36,10 @@ release = version
 # directories to ignore when looking for source files.
 exclude_patterns = ['_build']
 
-if os.environ.get('WITH_EMACS') == '1':
+if tags.has('WITH_EMACS'):
     # Hacky reimplementation of include to workaround limitations of
     # sphinx-doc
     lines = ['.. include:: /../emacs/rstdoc.rsti\n\n'] # in the source tree
-    rsti_dir = os.environ.get('RSTI_DIR')
-    # the other files are from the build tree
     for file in ('notmuch.rsti', 'notmuch-lib.rsti', 'notmuch-show.rsti', 'notmuch-tag.rsti'):
         lines.extend(open(rsti_dir+'/'+file))
     rst_epilog = ''.join(lines)