diff --git a/sphinx_multiversion/sphinx.py b/sphinx_multiversion/sphinx.py index ad14f0c4..610f25f1 100644 --- a/sphinx_multiversion/sphinx.py +++ b/sphinx_multiversion/sphinx.py @@ -157,7 +157,12 @@ def apathto(self, build_target_name, build_target): """Find the path to the artefact identified by build_target_name and build_target. """ - artefact_dir = "artefacts" + current_version = self.metadata[self.current_version_name] + current_outputroot = os.path.abspath(current_version["outputdir"]) + artefact_dir = posixpath.join(current_outputroot, "artefacts") + current_outputdir = posixpath.dirname( + posixpath.join(current_outputroot, self.context["pagename"]) + ) filename = "{project}_docs-{version}".format( project=self.app.config.project.replace(" ", ""), @@ -175,8 +180,9 @@ def apathto(self, build_target_name, build_target): f=filename, extension=build_target["download_format"], ) - artefact_path = posixpath.join(artefact_dir, filename) - + artefact_path = posixpath.relpath( + posixpath.join(artefact_dir, filename), start=current_outputdir + ) return artefact_path diff --git a/tests/test_sphinx.py b/tests/test_sphinx.py index 04024018..33cd7b99 100644 --- a/tests/test_sphinx.py +++ b/tests/test_sphinx.py @@ -160,15 +160,43 @@ def test_apathto(self): ) self.assertEqual( self.versioninfo.apathto("PDF", build_targets["PDF"]), - "artefacts/example_docs-master.pdf", + posixpath.join("artefacts", "example_docs-master.pdf"), ) - mock_versioninfo = self.versioninfo - mock_versioninfo.current_version_name = "branch-with/slash" + self.versioninfo.context["pagename"] = "appendix/faq" + self.assertEqual( + self.versioninfo.apathto("PDF", build_targets["PDF"]), + posixpath.join("..", "artefacts", "example_docs-master.pdf"), + ) - self.versioninfo = Mock() - self.versioninfo = mock_versioninfo + self.versioninfo.context["pagename"] = "testpage" + self.versioninfo.current_version_name = "branch-with/slash" + self.assertEqual( + self.versioninfo.apathto("PDF", build_targets["PDF"]), + posixpath.join("artefacts", "example_docs-branch-with-slash.pdf"), + ) + self.assertEqual( + self.versioninfo.apathto("HTML", build_targets["HTML"]), + posixpath.join( + "artefacts", "example_docs-branch-with-slash-HTML.zip" + ), + ) + + self.versioninfo.app.config.project = ( + "Project Name with Spaces and VaRiAbLe case" + ) + self.versioninfo.current_version_name = "master" + self.assertEqual( + self.versioninfo.apathto("HTML", build_targets["HTML"]), + posixpath.join( + "artefacts", + "ProjectNamewithSpacesandVaRiAbLecase_docs-master-HTML.zip", + ), + ) self.assertEqual( self.versioninfo.apathto("PDF", build_targets["PDF"]), - "artefacts/example_docs-branch-with-slash.pdf", + posixpath.join( + "artefacts", + "ProjectNamewithSpacesandVaRiAbLecase_docs-master.pdf", + ), )