Skip to content

Commit 83d5069

Browse files
committed
sphinx: Fix vpathto for branch names containing slashes on Windows
This fixes an issue where forward slashes in branch names would be converted to backward slashes on Windows. Resolves #31.
1 parent b4b383c commit 83d5069

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

sphinx_multiversion/sphinx.py

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# -*- coding: utf-8 -*-
22
import datetime
33
import json
4-
import pathlib
54
import collections
65
import logging
76
import os
@@ -97,39 +96,39 @@ def vpathto(self, other_version_name):
9796
posixpath.split(self.context["pagename"])[-1]
9897
)
9998

100-
# Find output root
99+
# Find relative outputdir paths from common output root
101100
current_version = self.metadata[self.current_version_name]
102101
other_version = self.metadata[other_version_name]
103-
outputroot = os.path.commonpath(
104-
(current_version["outputdir"], other_version["outputdir"])
102+
103+
current_outputroot = os.path.abspath(current_version["outputdir"])
104+
other_outputroot = os.path.abspath(other_version["outputdir"])
105+
outputroot = os.path.commonpath((current_outputroot, other_outputroot))
106+
107+
current_outputroot = os.path.relpath(
108+
current_outputroot, start=outputroot
105109
)
110+
other_outputroot = os.path.relpath(other_outputroot, start=outputroot)
106111

107-
current_outputroot = pathlib.PurePath(
108-
current_version["outputdir"]
109-
).relative_to(outputroot)
110-
other_outputroot = pathlib.PurePath(
111-
other_version["outputdir"]
112-
).relative_to(outputroot)
113-
114-
relative_path_to_outputroot = os.path.join(
115-
*(
116-
".."
117-
for x in current_outputroot.joinpath(
118-
self.context["pagename"]
119-
).parent.parts
112+
# Ensure that we use POSIX separators in the path (for the HTML code)
113+
if os.sep != posixpath.sep:
114+
current_outputroot = posixpath.join(
115+
*os.path.split(current_outputroot)
120116
)
121-
)
117+
other_outputroot = posixpath.join(*os.path.split(other_outputroot))
122118

123-
# Find output dir of other version
124-
outputdir = posixpath.join(
125-
relative_path_to_outputroot, other_outputroot
119+
# Find relative path to root of other_version's outputdir
120+
current_outputdir = posixpath.dirname(
121+
posixpath.join(current_outputroot, self.context["pagename"])
122+
)
123+
other_outputdir = posixpath.relpath(
124+
other_outputroot, start=current_outputdir
126125
)
127126

128127
if not self.vhasdoc(other_version_name):
129-
return posixpath.join(outputdir, "index.html")
128+
return posixpath.join(other_outputdir, "index.html")
130129

131130
return posixpath.join(
132-
outputdir, "{}.html".format(self.context["pagename"])
131+
other_outputdir, "{}.html".format(self.context["pagename"])
133132
)
134133

135134

0 commit comments

Comments
 (0)