From 02a5c1fc2f2aba49d689b140cead8efefc2fd1bf Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Tue, 3 Jun 2014 13:42:33 +0100 Subject: [PATCH] Disable screenshot generating in doc-test mode. They are not necessary and they slow down the build quite considerably. Refs #9562 --- Code/Mantid/docs/CMakeLists.txt | 1 + Code/Mantid/docs/runsphinx.py.in | 4 ++- .../mantiddoc/directives/algorithm.py | 30 ++++++++++++------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Code/Mantid/docs/CMakeLists.txt b/Code/Mantid/docs/CMakeLists.txt index 7b9dc0f3d82..97c42b78a71 100644 --- a/Code/Mantid/docs/CMakeLists.txt +++ b/Code/Mantid/docs/CMakeLists.txt @@ -28,6 +28,7 @@ if ( SPHINX_FOUND ) # doctest target set ( BUILDER doctest ) + set ( SCREENSHOTS_DIR "" ) # no screenshots configure_file ( runsphinx.py.in runsphinx_doctest.py @ONLY ) add_custom_target ( ${TARGET_PREFIX}-test COMMAND ${DOCS_RUNNER_EXE} -xq runsphinx_doctest.py diff --git a/Code/Mantid/docs/runsphinx.py.in b/Code/Mantid/docs/runsphinx.py.in index 02316f03b62..6d6c3b6e135 100644 --- a/Code/Mantid/docs/runsphinx.py.in +++ b/Code/Mantid/docs/runsphinx.py.in @@ -6,7 +6,9 @@ import os import sys # set environment -os.environ["SCREENSHOTS_DIR"] = "@SCREENSHOTS_DIR@" +screenshots_dir = "@SCREENSHOTS_DIR@" +if screenshots_dir != "": + os.environ["SCREENSHOTS_DIR"] = screenshots_dir builder = "@BUILDER@" src_dir = "@CMAKE_CURRENT_SOURCE_DIR@/source" diff --git a/Code/Mantid/docs/sphinxext/mantiddoc/directives/algorithm.py b/Code/Mantid/docs/sphinxext/mantiddoc/directives/algorithm.py index 6bdd47891cf..d28be977d7e 100644 --- a/Code/Mantid/docs/sphinxext/mantiddoc/directives/algorithm.py +++ b/Code/Mantid/docs/sphinxext/mantiddoc/directives/algorithm.py @@ -108,18 +108,23 @@ class AlgorithmDirective(BaseDirective): Returns: str: The full path to the created image """ - from mantiddoc.tools.screenshot import algorithm_screenshot + notfoundimage = "/images/ImageNotFound.png" + try: + screenshots_dir = self._screenshot_directory() + except RuntimeError: + return notfoundimage - env = self.state.document.settings.env - screenshots_dir = self._screenshot_directory() + # Generate image + from mantiddoc.tools.screenshot import algorithm_screenshot if not os.path.exists(screenshots_dir): os.makedirs(screenshots_dir) try: imgpath = algorithm_screenshot(self.algorithm_name(), screenshots_dir, version=self.algorithm_version()) except Exception, exc: + env = self.state.document.settings.env env.warn(env.docname, "Unable to generate screenshot for '%s' - %s" % (algorithm_name, str(exc))) - imgpath = os.path.join(screenshots_dir, "ImageNotFound.png") + imgpath = notfoundimage return imgpath @@ -144,13 +149,18 @@ class AlgorithmDirective(BaseDirective): filename = os.path.split(img_path)[1] cfgdir = env.srcdir - screenshots_dir = self._screenshot_directory() - rel_path = os.path.relpath(screenshots_dir, cfgdir) - # This is a href link so is expected to be in unix style - rel_path = rel_path.replace("\\","/") - # stick a "/" as the first character so Sphinx computes relative location from source directory - path = "/" + rel_path + "/" + filename + try: + screenshots_dir = self._screenshot_directory() + rel_path = os.path.relpath(screenshots_dir, cfgdir) + # This is a href link so is expected to be in unix style + rel_path = rel_path.replace("\\","/") + # stick a "/" as the first character so Sphinx computes relative location from source directory + path = "/" + rel_path + "/" + filename + except RuntimeError: + # Use path as it is + path = img_path + caption = "A screenshot of the **" + self.algorithm_name() + "** dialog." self.add_rst(format_str % (path, caption)) -- GitLab