Browse Source

Fix handling of absolute paths

Jan Holthuis 5 years ago
parent
commit
e7dfaff99b
4 changed files with 34 additions and 7 deletions
  1. 9 0
      docs/changelog.rst
  2. 1 1
      docs/conf.py
  3. 1 1
      setup.py
  4. 23 5
      sphinx_multiversion/sphinx.py

+ 9 - 0
docs/changelog.rst

@@ -7,6 +7,15 @@ Changelog
 Version 0.2
 ===========
 
+Version 0.2.1
+-------------
+
+* Fix handling of absolute output paths in `vpathto` and ensure that all generated paths are relative.
+
+
+Version 0.2.0
+-------------
+
 * Added a way to override config variables using placeholders that expand to each version's actual value (`#4 <issue4_>`_, `#7 <issue7_>`_).
 
 

+ 1 - 1
docs/conf.py

@@ -4,7 +4,7 @@ import time
 
 author = "Jan Holthuis"
 project = "sphinx-multiversion"
-release = "0.2.0"
+release = "0.2.1"
 version = "0.2"
 copyright = "{}, {}".format(time.strftime("%Y"), author)
 

+ 1 - 1
setup.py

@@ -20,7 +20,7 @@ setup(
     author="Jan Holthuis",
     author_email="[email protected]",
     url="https://holzhaus.github.io/sphinx-multiversion/",
-    version="0.2.0",
+    version="0.2.1",
     install_requires=["sphinx >= 2.1"],
     license="BSD",
     packages=["sphinx_multiversion"],

+ 23 - 5
sphinx_multiversion/sphinx.py

@@ -99,13 +99,31 @@ class VersionInfo:
 
         # Find output root
         current_version = self.metadata[self.current_version_name]
-        relpath = pathlib.PurePath(current_version["outputdir"])
-        relpath_dir = relpath.joinpath(self.context["pagename"]).parent
-        outputroot = os.path.join(*(".." for x in relpath_dir.parts))
+        other_version = self.metadata[other_version_name]
+        outputroot = os.path.commonpath(
+            (current_version["outputdir"], other_version["outputdir"])
+        )
+
+        current_outputroot = pathlib.PurePath(
+            current_version["outputdir"]
+        ).relative_to(outputroot)
+        other_outputroot = pathlib.PurePath(
+            other_version["outputdir"]
+        ).relative_to(outputroot)
+
+        relative_path_to_outputroot = os.path.join(
+            *(
+                ".."
+                for x in current_outputroot.joinpath(
+                    self.context["pagename"]
+                ).parent.parts
+            )
+        )
 
         # Find output dir of other version
-        other_version = self.metadata[other_version_name]
-        outputdir = posixpath.join(outputroot, other_version["outputdir"])
+        outputdir = posixpath.join(
+            relative_path_to_outputroot, other_outputroot
+        )
 
         if not self.vhasdoc(other_version_name):
             return posixpath.join(outputdir, "index.html")