Parcourir la source

Allow variable substitution in command line defines

Attempt to fix edge cases where other extensions need to know about the
actual source path.

Resolves: #4
Jan Holthuis il y a 5 ans
Parent
commit
b4b5cc6281
1 fichiers modifiés avec 13 ajouts et 5 suppressions
  1. 13 5
      sphinx_multiversion/main.py

+ 13 - 5
sphinx_multiversion/main.py

@@ -6,6 +6,7 @@ import logging
 import os
 import pathlib
 import re
+import string
 import subprocess
 import sys
 import tempfile
@@ -199,22 +200,29 @@ def main(argv=None):
         # Run Sphinx
         argv.extend(["-D", "smv_metadata_path={}".format(metadata_path)])
         for version_name, data in metadata.items():
-            outdir = os.path.join(args.outputdir, data["outputdir"])
-            os.makedirs(outdir, exist_ok=True)
+            data["confdir"] = confdir
+            data["outputdir"] = os.path.join(args.outputdir, data["outputdir"])
+            os.makedirs(data["outputdir"], exist_ok=True)
+
+            defines = itertools.chain(*(
+                ("-D", string.Template(d).safe_substitute(data))
+                for d in args.define
+            ))
 
             current_argv = argv.copy()
             current_argv.extend(
                 [
-                    *itertools.chain(*(("-D", d) for d in args.define)),
+                    *defines,
                     "-D",
                     "smv_current_version={}".format(version_name),
                     "-c",
-                    confdir,
+                    data["confdir"],
                     data["sourcedir"],
-                    outdir,
+                    data["outputdir"],
                     *args.filenames,
                 ]
             )
+            logger.debug("Running sphinx-build with args: %r", current_argv)
             status = sphinx_build.build_main(current_argv)
             if status not in (0, None):
                 break