Эх сурвалжийг харах

Merge pull request #13 from Holzhaus/confdir-bug

Fix usage of sourcedir instead of confdir in sphinx extension
Jan Holthuis 4 жил өмнө
parent
commit
bda14735f9

+ 3 - 0
docs/changelog.rst

@@ -11,6 +11,7 @@ Version 0.2.4 (unreleased)
 --------------------------
 
 * Skip file existence check for the :file:`.` directory. This fixes an issue if the configuration or source directory is in the local path but reported as missing, because ``git cat-file -e`` always reports an error in that case. (`#12 <issue12_>`_)
+* Fix bug in the sphinx extension which tried to load the `conf.py` from the source directory instead of the conf directory. This could lead to problems when the two directories differ. (`#11 <issue11_>`_, `#13 <issue11_>`_)
 
 
 Version 0.2.3
@@ -57,4 +58,6 @@ Version 0.1.0
 .. _issue4: https://github.com/Holzhaus/sphinx-multiversion/issues/4
 .. _issue7: https://github.com/Holzhaus/sphinx-multiversion/issues/7
 .. _issue9: https://github.com/Holzhaus/sphinx-multiversion/issues/9
+.. _issue11: https://github.com/Holzhaus/sphinx-multiversion/issues/11
 .. _issue12: https://github.com/Holzhaus/sphinx-multiversion/issues/12
+.. _issue13: https://github.com/Holzhaus/sphinx-multiversion/issues/13

+ 11 - 7
sphinx_multiversion/main.py

@@ -63,6 +63,13 @@ def main(argv=None):
     if args.noconfig:
         return 1
 
+    sourcedir_absolute = os.path.abspath(args.sourcedir)
+    confdir_absolute = (
+        os.path.abspath(args.confdir)
+        if args.confdir is not None
+        else sourcedir_absolute
+    )
+
     # Conf-overrides
     confoverrides = {}
     for d in args.define:
@@ -70,10 +77,7 @@ def main(argv=None):
         confoverrides[key] = value
 
     # Parse config
-    config = sphinx_config.Config.read(
-        os.path.abspath(args.confdir if args.confdir else args.sourcedir),
-        confoverrides,
-    )
+    config = sphinx_config.Config.read(confdir_absolute, confoverrides)
     config.add("smv_tag_whitelist", sphinx.DEFAULT_TAG_WHITELIST, "html", str)
     config.add(
         "smv_branch_whitelist", sphinx.DEFAULT_TAG_WHITELIST, "html", str
@@ -93,9 +97,9 @@ def main(argv=None):
 
     # Get relative paths to root of git repository
     gitroot = pathlib.Path(".").resolve()
-    sourcedir = os.path.relpath(args.sourcedir, str(gitroot))
+    sourcedir = os.path.relpath(sourcedir_absolute, str(gitroot))
     if args.confdir:
-        confdir = os.path.relpath(args.confdir, str(gitroot))
+        confdir = os.path.relpath(confdir_absolute, str(gitroot))
     else:
         confdir = sourcedir
     conffile = os.path.join(confdir, "conf.py")
@@ -185,7 +189,7 @@ def main(argv=None):
                 "outputdir": os.path.join(
                     os.path.abspath(args.outputdir), outputdir
                 ),
-                "confdir": os.path.abspath(confdir),
+                "confdir": confpath,
                 "docnames": list(project.discover()),
             }
 

+ 1 - 1
sphinx_multiversion/sphinx.py

@@ -171,7 +171,7 @@ def config_inited(app, config):
     app.connect("html-page-context", html_page_context)
 
     # Restore config values
-    old_config = sphinx_config.Config.read(app.srcdir)
+    old_config = sphinx_config.Config.read(app.confdir)
     old_config.pre_init_values()
     old_config.init_values()
     config.version = old_config.version