From d638a3d2f7f2c6be6ad983922e1fef7f30d1cd7e Mon Sep 17 00:00:00 2001 From: Gabriel Hottiger Date: Fri, 5 Jul 2019 10:26:20 +0200 Subject: [PATCH] fix pdf path and remove latex temporary folders --- sphinxcontrib/versioning/sphinx_.py | 6 ++++-- sphinxcontrib/versioning/versions.py | 18 ++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sphinxcontrib/versioning/sphinx_.py b/sphinxcontrib/versioning/sphinx_.py index ed42f6e..0b08f20 100644 --- a/sphinxcontrib/versioning/sphinx_.py +++ b/sphinxcontrib/versioning/sphinx_.py @@ -5,7 +5,7 @@ import logging import multiprocessing import os import sys -from shutil import copyfile +from shutil import copyfile, rmtree from sphinx import application, locale from sphinx.cmd.build import build_main, make_main @@ -214,7 +214,9 @@ def _build(argv, config, versions, current_name, is_root): args = map(unicode, args) result = make_main(args) # Copy to _static dir of src - copyfile(argv[1] + unicode("/latex/" + config.pdf_file), argv[0] + unicode("/_static/" + config.pdf_file)) + latexDir = argv[1] + unicode("/latex/"); + copyfile( latexDir + config.pdf_file, argv[0] + unicode("/_static/" + config.pdf_file)) + rmtree(latexDir) # Build. result = build_main(argv) diff --git a/sphinxcontrib/versioning/versions.py b/sphinxcontrib/versioning/versions.py index 3dceda4..b199228 100644 --- a/sphinxcontrib/versioning/versions.py +++ b/sphinxcontrib/versioning/versions.py @@ -197,12 +197,12 @@ class Versions(object): @property def branches(self): """Return list of (name and urls, pdf_urls) only branches.""" - return [(r['name'], self.vpathto(r['name']), os.path.dirname(self.vpathto(r['name'])) + "/_static/" + self.pdf_file) for r in self.remotes if r['kind'] == 'heads'] + return [(r['name'], self.vpathto(r['name']), self.pathtopdf(r['name'])) for r in self.remotes if r['kind'] == 'heads'] @property def tags(self): """Return list of (name and urls, pdf_urls) only tags.""" - return [(r['name'], self.vpathto(r['name']), os.path.dirname(self.vpathto(r['name'])) + "/_static/" + self.pdf_file) for r in self.remotes if r['kind'] == 'tags'] + return [(r['name'], self.vpathto(r['name']), self.pathtopdf(r['name'])) for r in self.remotes if r['kind'] == 'tags'] def vhasdoc(self, other_version): """Return True if the other version has the current document. Like Sphinx's hasdoc(). @@ -241,3 +241,17 @@ class Versions(object): components += [other_root_dir] if is_root else ['..', other_root_dir] components += [pagename if self.vhasdoc(other_version) else other_remote['master_doc']] return '{}.html'.format(__import__('posixpath').join(*components)) + + def pathtopdf(self, other_version): + is_root = self.context['scv_is_root'] + pagename = self.context['pagename'] + # if self.context['current_version'] == other_version and not is_root: + # return '{}.html'.format(pagename.split('/')[-1]) + + other_remote = self[other_version] + other_root_dir = other_remote['root_dir'] + components = ['..'] * pagename.count('/') + components += [other_root_dir] if is_root else ['..', other_root_dir] + components += ["_static"] + components += [os.path.splitext(self.pdf_file)[0]] + return '{}.pdf'.format(__import__('posixpath').join(*components))