source: sasview/docs/sphinx-docs/build_sphinx.py @ 9706d88

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalcmagnetic_scattrelease-4.2.2ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 9706d88 was 6e546f8, checked in by wojciech, 7 years ago

Latex file name fixed

  • Property mode set to 100755
File size: 20.1 KB
RevLine 
[9bf64f6]1#!/usr/bin/env python
[35bf493]2"""
3Functions for building sphinx docs.
4
5For more information on the invocation of sphinx see:
6http://sphinx-doc.org/invocation.html
7"""
[01f1e17]8from __future__ import print_function
9
[35bf493]10import subprocess
11import os
12import sys
13import fnmatch
14import shutil
[296f290]15import imp
[35bf493]16
[21bba86]17from glob import glob
[35bf493]18from distutils.dir_util import copy_tree
19from distutils.util import get_platform
[1573220]20from distutils.spawn import find_executable
21
[d2143ab]22from shutil import copy
[b7a2ebfd]23from os import listdir
[35bf493]24
[90d9cd3]25platform = '.%s-%s'%(get_platform(),sys.version[:3])
[35bf493]26
27CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
28
[296f290]29run = imp.load_source('run', os.path.join(CURRENT_SCRIPT_DIR, '..', '..', 'run.py'))
30run.prepare()
31
[35bf493]32SASVIEW_SRC = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "src")
33SASVIEW_BUILD = os.path.abspath(os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "build", "lib"+platform))
34SASVIEW_DOCS = os.path.join(SASVIEW_BUILD, "doc")
[2fb09c4]35SASVIEW_TEST = os.path.join(SASVIEW_SRC, "..", "sasview", "test", "media")
[5dd7499]36SASVIEW_TOC_SOURCE = os.path.join(CURRENT_SCRIPT_DIR, "source")
[35bf493]37
[5802e7b]38# Need to slurp in the new sasmodels model definitions to replace the old model_functions.rst
39# We are currently here:
40#/sasview-local-trunk/docs/sphinx-docs/build_sphinx.py
[a728658]41SASMODELS_SOURCE_PROLOG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc")
[4abc05d8]42SASMODELS_SOURCE_GPU = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "gpu")
43SASMODELS_SOURCE_SESANS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "sesans")
44SASMODELS_SOURCE_SESANSIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "sesans", "sesans_img")
45SASMODELS_SOURCE_MAGNETISM = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "magnetism")
46SASMODELS_SOURCE_MAGIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "magnetism", "mag_img")
47SASMODELS_SOURCE_REF_MODELS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "guide", "models")
[354524d]48SASMODELS_SOURCE_MODELS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model")
49SASMODELS_SOURCE_IMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model", "img")
[90d9cd3]50SASMODELS_SOURCE_AUTOIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "_build", "html","_images")
[5dd7499]51## Don't do assemble-in-place
52## Assemble the docs in a temporary folder
53SASMODELS_DEST_PROLOG = os.path.join(CURRENT_SCRIPT_DIR, "source-temp")
54SASMODELS_DEST_REF_MODELS = os.path.join(SASMODELS_DEST_PROLOG, "user")
55SASMODELS_DEST_MODELS = os.path.join(SASMODELS_DEST_PROLOG, "user", "models")
56SASMODELS_DEST_IMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "model-imgs", "new-models")
57SASMODELS_DEST_MAGIMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "mag_img")
[dd72190]58SASMODELS_DEST_SESANSIMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "sesans_img")
[5dd7499]59SASMODELS_DEST_BUILDIMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "models", "img")
[5802e7b]60
61
[35bf493]62SPHINX_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build")
[5dd7499]63SPHINX_SOURCE = os.path.join(CURRENT_SCRIPT_DIR, "source-temp")
[35bf493]64SPHINX_SOURCE_API = os.path.join(SPHINX_SOURCE, "dev", "api")
[ba31ed1]65SPHINX_SOURCE_GUIFRAME = os.path.join(SPHINX_SOURCE, "user", "sasgui", "guiframe")
[7168b8b]66SPHINX_SOURCE_MODELS = os.path.join(SPHINX_SOURCE, "user", "models")
[ba31ed1]67SPHINX_SOURCE_PERSPECTIVES = os.path.join(SPHINX_SOURCE, "user", "sasgui", "perspectives")
[2fb09c4]68SPHINX_SOURCE_TEST = os.path.join(SPHINX_SOURCE, "test")
[578a11d]69SPHINX_SOURCE_USER = os.path.join(SPHINX_SOURCE, "user")
[35bf493]70
[c22c5e3]71BUMPS_DOCS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..",
72                          "bumps", "doc", "guide")
73BUMPS_TARGET = os.path.join(SPHINX_SOURCE_PERSPECTIVES, "fitting")
74
[bb0c836]75def inplace_change(filename, old_string, new_string):
76# Thanks to http://stackoverflow.com/questions/4128144/replace-string-within-file-contents
[90d9cd3]77        s=open(filename).read()
78        if old_string in s:
79                print('Changing "{old_string}" to "{new_string}"'.format(**locals()))
80                s=s.replace(old_string, new_string)
81                f=open(filename, 'w')
82                f.write(s)
83                f.flush()
84                f.close()
85        else:
86                print('No occurences of "{old_string}" found.'.format(**locals()))
[bb0c836]87
[35bf493]88def _remove_dir(dir_path):
89    """Removes the given directory."""
90    if os.path.isdir(dir_path):
[21bba86]91        print("Removing \"%s\"... " % dir_path)
[35bf493]92        shutil.rmtree(dir_path)
93
94def clean():
95    """
96    Clean the sphinx build directory.
97    """
[f4d571b]98    print("=== Cleaning Sphinx Build ===")
[35bf493]99    _remove_dir(SASVIEW_DOCS)
100    _remove_dir(SPHINX_BUILD)
[5dd7499]101    _remove_dir(SPHINX_SOURCE)
102    #_remove_dir(SPHINX_SOURCE_GUIFRAME)
103    #_remove_dir(SPHINX_SOURCE_MODELS)
104    #_remove_dir(SPHINX_SOURCE_PERSPECTIVES)
105    #_remove_dir(SPHINX_SOURCE_TEST)
[35bf493]106
[5dd7499]107def setup_source_temp():
108    """
109    Copy the source toctrees to new folder for assembling the sphinx-docs
110    """
[f4d571b]111    print("=== Copying Source toctrees ===")
[5dd7499]112    if os.path.exists(SASVIEW_TOC_SOURCE):
[90d9cd3]113       print("Found docs folder at", SASVIEW_TOC_SOURCE)
114       shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE)
[354524d]115
[35bf493]116def retrieve_user_docs():
117    """
118    Copies across the contents of any media/ directories in src/, and puts them
119    in an appropriately named directory of docs/sphinx-docs/source/. For
120    example:
121
122        sas/../[MODULE]/media/dir/A.rst
123        sas/../[MODULE]/media/B.rst
124
125    gets copied to a new location:
126
127        docs/sphinx-docs/source/user/[MODULE]/dir/A.rst
128        docs/sphinx-docs/source/user/[MODULE]/B.rst
129
130    so that Sphinx may pick it up when generating the documentation.
131    """
[f4d571b]132    print("=== Retrieve User Docs ===")
[35bf493]133
134    # Copy documentation files from their "source" to their "destination".
135    for root, dirnames, _ in os.walk(SASVIEW_SRC):
136        for dirname in fnmatch.filter(dirnames, 'media'):
137
138            docs = os.path.abspath(os.path.join(root, dirname))
[f4d571b]139            print("Found docs folder at \"%s\"." % docs)
[35bf493]140
[f620870]141            dest_dir_part = os.path.dirname(os.path.relpath(docs, SASVIEW_SRC))
142            if os.sep in dest_dir_part:
143                dest_dir_part = dest_dir_part[dest_dir_part.index(os.sep) + 1:]
144            dest_dir = os.path.join(SPHINX_SOURCE, "user", dest_dir_part)
[35bf493]145
146            copy_tree(docs, dest_dir)
[8096b446]147
[2fb09c4]148    # Now pickup testdata_help.rst
[f4d571b]149    print("=== Including Test Data Docs ===")
[2fb09c4]150    if os.path.exists(SASVIEW_TEST):
[90d9cd3]151       print("Found docs folder at", SASVIEW_TEST)
152       shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST)
[354524d]153
[f4d571b]154    print("=== And the Sasmodels Docs ===")
[6a9c0e5a]155    # Make sure we have the relevant images for the new sasmodels documentation
[90d9cd3]156    # First(!) we'll make a local reference copy for SasView (/new-models will be cleaned each build)
[b7a2ebfd]157    if os.path.exists(SASMODELS_SOURCE_IMG):
[f4d571b]158        print("Found img folder SASMODELS_SOURCE_IMG at", SASMODELS_SOURCE_IMG)
[6de5e10]159        if not os.path.exists(SASMODELS_DEST_IMG):
[f4d571b]160            print("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG)
[6de5e10]161            os.makedirs(SASMODELS_DEST_IMG)
[f4d571b]162            print("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG)
163        else:
164            print("Found img folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG)
165        print("Copying sasmodels model image files...")
[6de5e10]166        for files in os.listdir(SASMODELS_SOURCE_IMG):
[90d9cd3]167            fromhere=os.path.join(SASMODELS_SOURCE_IMG,files)
168            tohere=os.path.join(SASMODELS_DEST_IMG,files)
169            shutil.copy(fromhere,tohere)
[f4d571b]170    else:
[90d9cd3]171        print("no source directory",SASMODELS_SOURCE_IMG,"was found")
[b7a2ebfd]172
[5420ef6]173    if os.path.exists(SASMODELS_SOURCE_AUTOIMG):
[f4d571b]174        print("Found img folder SASMODELS_SOURCE_AUTOIMG at", SASMODELS_SOURCE_AUTOIMG)
[6de5e10]175        if not os.path.exists(SASMODELS_DEST_IMG):
[f4d571b]176            print("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG)
[6de5e10]177            os.makedirs(SASMODELS_DEST_BUILDIMG)
[f4d571b]178            print("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG)
179        print("Copying sasmodels model auto-generated image files...")
[6de5e10]180        for files in os.listdir(SASMODELS_SOURCE_AUTOIMG):
[90d9cd3]181            fromhere=os.path.join(SASMODELS_SOURCE_AUTOIMG,files)
182            tohere=os.path.join(SASMODELS_DEST_IMG,files)
183            shutil.copy(fromhere,tohere)
[f4d571b]184    else:
[90d9cd3]185        print("no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found")
[8096b446]186
[a728658]187    # And the rst prolog with the unit substitutions
188    if os.path.exists(SASMODELS_SOURCE_PROLOG):
[f4d571b]189        print("Found prolog folder SASMODELS_SOURCE_PROLOG at", SASMODELS_SOURCE_PROLOG)
[a728658]190        if os.path.exists(SASMODELS_DEST_PROLOG):
[f4d571b]191            print("Found docs folder SASMODELS_DEST_PROLOG at", SASMODELS_DEST_PROLOG)
192            print("Copying sasmodels rst_prolog file...")
[a728658]193            for files in os.listdir(SASMODELS_SOURCE_PROLOG):
194                if files.startswith("rst"):
[90d9cd3]195                    fromhere=os.path.join(SASMODELS_SOURCE_PROLOG,files)
196                    tohere=os.path.join(SASMODELS_DEST_PROLOG,files)
197                    shutil.copy(fromhere,tohere)
[f4d571b]198    else:
[90d9cd3]199        print("no source directory",SASMODELS_SOURCE_PROLOG, "was found")
[a728658]200
[dd72190]201    if os.path.exists(SASMODELS_SOURCE_GPU):
[f4d571b]202        print("Found docs folder SASMODELS_SOURCE_GPU at", SASMODELS_SOURCE_GPU)
[dd72190]203        if os.path.exists(SPHINX_SOURCE_USER):
[f4d571b]204            print("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER)
205            print("Copying sasmodels gpu files...")
[dd72190]206            for files in os.listdir(SASMODELS_SOURCE_GPU):
207                if files.endswith(".rst"):
[90d9cd3]208                    fromhere=os.path.join(SASMODELS_SOURCE_GPU,files)
209                    tohere=os.path.join(SPHINX_SOURCE_USER,files)
210                    shutil.copy(fromhere,tohere)
[f4d571b]211    else:
[90d9cd3]212        print("no source directory",SASMODELS_SOURCE_GPU,"was found")
[dd72190]213
[578a11d]214    if os.path.exists(SASMODELS_SOURCE_SESANS):
[f4d571b]215        print("Found docs folder SASMODELS_SOURCE_SESANS at", SASMODELS_SOURCE_SESANS)
[578a11d]216        if os.path.exists(SPHINX_SOURCE_USER):
[f4d571b]217            print("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER)
218            print("Copying sasmodels sesans files...")
[578a11d]219            for files in os.listdir(SASMODELS_SOURCE_SESANS):
220                if files.endswith(".rst"):
[90d9cd3]221                    fromhere=os.path.join(SASMODELS_SOURCE_SESANS,files)
222                    tohere=os.path.join(SPHINX_SOURCE_USER,files)
223                    shutil.copy(fromhere,tohere)
[f4d571b]224    else:
[90d9cd3]225        print("no source directory",SASMODELS_SOURCE_SESANS,"was found")
[578a11d]226
[18a1f2b]227    if os.path.exists(SASMODELS_SOURCE_MAGNETISM):
[f4d571b]228        print("Found docs folder SASMODELS_SOURCE_MAGNETISM at", SASMODELS_SOURCE_MAGNETISM)
[18a1f2b]229        if os.path.exists(SASMODELS_DEST_REF_MODELS):
[f4d571b]230            print("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS)
231            print("Copying sasmodels model toctree files...")
[18a1f2b]232            for files in os.listdir(SASMODELS_SOURCE_MAGNETISM):
233                if files.endswith(".rst"):
[90d9cd3]234                    fromhere=os.path.join(SASMODELS_SOURCE_MAGNETISM,files)
235                    tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files)
236                    shutil.copy(fromhere,tohere)
[f4d571b]237    else:
[90d9cd3]238        print("no source directory",SASMODELS_SOURCE_MAGNETISM,"was found")
[18a1f2b]239
[8096b446]240    if os.path.exists(SASMODELS_SOURCE_MAGIMG):
[f4d571b]241        print("Found img folder SASMODELS_SOURCE_MAGIMG   at", SASMODELS_SOURCE_MAGIMG)
[8096b446]242        if not os.path.exists(SASMODELS_DEST_MAGIMG):
[f4d571b]243            print("Missing img folder SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG)
[8096b446]244            os.makedirs(SASMODELS_DEST_MAGIMG)
[f4d571b]245            print("created SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG)
246        print("Copying sasmodels mag image files...")
[8096b446]247        for files in os.listdir(SASMODELS_SOURCE_MAGIMG):
[90d9cd3]248            fromhere=os.path.join(SASMODELS_SOURCE_MAGIMG,files)
249            tohere=os.path.join(SASMODELS_DEST_MAGIMG,files)
250            shutil.copy(fromhere,tohere)
[f4d571b]251    else:
[90d9cd3]252        print("no source directory",SASMODELS_SOURCE_MAGIMG ,"was found")
[dd72190]253
254    if os.path.exists(SASMODELS_SOURCE_SESANSIMG):
[f4d571b]255        print("Found img folder SASMODELS_SOURCE_SESANSIMG at", SASMODELS_SOURCE_SESANSIMG)
[751f4bd]256        if not os.path.exists(SASMODELS_DEST_SESANSIMG):
[f4d571b]257            print("Missing img folder SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG)
[dd72190]258            os.makedirs(SASMODELS_DEST_SESANSIMG)
[f4d571b]259            print("created SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG)
260        print("Copying sasmodels sesans image files...")
[dd72190]261        for files in os.listdir(SASMODELS_SOURCE_SESANSIMG):
[90d9cd3]262            fromhere=os.path.join(SASMODELS_SOURCE_SESANSIMG,files)
263            tohere=os.path.join(SASMODELS_DEST_SESANSIMG,files)
264            shutil.copy(fromhere,tohere)
[f4d571b]265    else:
[90d9cd3]266        print("no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found")
[8096b446]267
[bb0c836]268    if os.path.exists(SASMODELS_SOURCE_REF_MODELS):
[f4d571b]269        print("Found docs folder SASMODELS_SOURCE_REF_MODELS at", SASMODELS_SOURCE_REF_MODELS)
[bb0c836]270        if os.path.exists(SASMODELS_DEST_REF_MODELS):
[f4d571b]271            print("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS)
272            print("Copying sasmodels model toctree files...")
[bb0c836]273            for files in os.listdir(SASMODELS_SOURCE_REF_MODELS):
274                if files.endswith(".rst"):
[90d9cd3]275                    fromhere=os.path.join(SASMODELS_SOURCE_REF_MODELS,files)
276                    tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files)
277                    shutil.copy(fromhere,tohere)
[115eb7e]278            # But need to change the path to the model docs in the tocs
279            for files in os.listdir(SASMODELS_DEST_REF_MODELS):
280        #        print files
281                if files.startswith("shape"):
[f4d571b]282                    print("Changing toc paths in", files)
[90d9cd3]283                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/")
[115eb7e]284                if files.startswith("sphere"):
[f4d571b]285                    print("Changing toc paths in", files)
[90d9cd3]286                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/")
[115eb7e]287                if files.startswith("custom"):
[f4d571b]288                    print("Changing toc paths in", files)
[90d9cd3]289                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/")
[115eb7e]290                if files.startswith("structure"):
[f4d571b]291                    print("Changing toc paths in", files)
[90d9cd3]292                    inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/")
[f4d571b]293    else:
[90d9cd3]294        print("no source directory",SASMODELS_SOURCE_REF_MODELS," was found")
[a728658]295
[b7a2ebfd]296    if os.path.exists(SASMODELS_SOURCE_MODELS):
[f4d571b]297        print("Found docs folder SASMODELS_SOURCE_MODELS at", SASMODELS_SOURCE_MODELS)
[b7a2ebfd]298        if os.path.exists(SASMODELS_DEST_MODELS):
[f4d571b]299            print("Found docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS)
300            print("Copying sasmodels model files...")
[b7a2ebfd]301            for files in os.listdir(SASMODELS_SOURCE_MODELS):
[354524d]302                if files.endswith(".rst"):
[90d9cd3]303                    fromhere=os.path.join(SASMODELS_SOURCE_MODELS,files)
304                    tohere=os.path.join(SASMODELS_DEST_MODELS,files)
305                    shutil.copy(fromhere,tohere)
[5420ef6]306        else:
[f4d571b]307            print("Missing docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS)
[5420ef6]308            os.makedirs(SASMODELS_DEST_MODELS)
309            if not os.path.exists(SASMODELS_DEST_BUILDIMG):
310                os.makedirs(SASMODELS_DEST_BUILDIMG)
[f4d571b]311            print("Created docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS)
312            print("Copying model files for build...")
[5420ef6]313            for files in os.listdir(SASMODELS_SOURCE_MODELS):
314                if files.endswith(".rst"):
[90d9cd3]315                    fromhere=os.path.join(SASMODELS_SOURCE_MODELS,files)
316                    tohere=os.path.join(SASMODELS_DEST_MODELS,files)
317                    shutil.copy(fromhere,tohere)
[5420ef6]318            # No choice but to do this because model files are all coded for images in /models/img
[f4d571b]319            print("Copying image files for build...")
[5420ef6]320            for files in os.listdir(SASMODELS_DEST_IMG):
[90d9cd3]321                fromhere=os.path.join(SASMODELS_DEST_IMG,files)
322                tohere=os.path.join(SASMODELS_DEST_BUILDIMG,files)
323                shutil.copy(fromhere,tohere)
[f4d571b]324    else:
[90d9cd3]325        print("no source directory",SASMODELS_SOURCE_MODELS,"was found.")
[f4d571b]326        print("!!!!NO MODEL DOCS WILL BE BUILT!!!!")
[6a9c0e5a]327
[c22c5e3]328def retrieve_bumps_docs():
329    """
330    Copies select files from the bumps documentation into fitting perspective
331    """
332    if os.path.exists(BUMPS_DOCS):
[f4d571b]333        print("=== Retrieve BUMPS Docs ===")
[c22c5e3]334        filenames = [os.path.join(BUMPS_DOCS, "optimizer.rst")]
335        filenames += glob(os.path.join(BUMPS_DOCS, "dream-*.png"))
336        filenames += glob(os.path.join(BUMPS_DOCS, "fit-*.png"))
337        for f in filenames:
[f4d571b]338            print("Copying file", f)
[c22c5e3]339            shutil.copy(f, BUMPS_TARGET)
340    else:
[f4d571b]341        print("""
[01f1e17]342======= Error =======
343missing directory %s
[c22c5e3]344The documentation will not include the optimizer selection section.
345Checkout the bumps source tree and rebuild the docs.
[f4d571b]346""" % BUMPS_DOCS)
[c22c5e3]347
[35bf493]348def apidoc():
349    """
350    Runs sphinx-apidoc to generate .rst files from the docstrings in .py files
351    in the SasView build directory.
352    """
[f4d571b]353    print("=== Generate API Rest Files ===")
[35bf493]354
355    # Clean directory before generating a new version.
356    _remove_dir(SPHINX_SOURCE_API)
357
358    subprocess.call(["sphinx-apidoc",
359                     "-o", SPHINX_SOURCE_API, # Output dir.
360                     "-d", "8", # Max depth of TOC.
361                     SASVIEW_BUILD])
362
[3194371]363def build_pdf():
364    """
365    Runs sphinx-build for pdf.  Reads in all .rst files and spits out the final html.
366    """
367    print("=== Build PDF Docs from ReST Files ===")
368    subprocess.call(["sphinx-build",
369                     "-b", "latex", # Builder name. TODO: accept as arg to setup.py.
370                     "-d", os.path.join(SPHINX_BUILD, "doctrees"),
371                     SPHINX_SOURCE,
372                     os.path.join(SPHINX_BUILD, "latex")])
373
374    LATEXDIR = os.path.join(SPHINX_BUILD, "latex")
[1573220]375    #TODO: Does it need to be done so many time?
[3194371]376    def pdflatex():
[6e546f8]377        subprocess.call(["pdflatex", "SasView.tex"], cwd=LATEXDIR)
[3194371]378    pdflatex()
379    pdflatex()
380    pdflatex()
[6e546f8]381    subprocess.call(["makeindex", "-s", "python.ist", "SasView.idx"], cwd=LATEXDIR)
[3194371]382    pdflatex()
383    pdflatex()
384
385    print("=== Copy PDF to HTML Directory ===")
[6e546f8]386    source = os.path.join(LATEXDIR, "SasView.pdf")
387    target = os.path.join(SASVIEW_DOCS, "SasView.pdf")
[3194371]388    shutil.copyfile(source, target)
389
[35bf493]390def build():
391    """
392    Runs sphinx-build.  Reads in all .rst files and spits out the final html.
393    """
[3194371]394    print("=== Build HTML Docs from ReST Files ===")
[35bf493]395    subprocess.call(["sphinx-build",
396                     "-b", "html", # Builder name. TODO: accept as arg to setup.py.
397                     "-d", os.path.join(SPHINX_BUILD, "doctrees"),
398                     SPHINX_SOURCE,
399                     os.path.join(SPHINX_BUILD, "html")])
400
[f4d571b]401    print("=== Copy HTML Docs to Build Directory ===")
[35bf493]402    html = os.path.join(SPHINX_BUILD, "html")
403    copy_tree(html, SASVIEW_DOCS)
404
[f4771596]405def fetch_katex(version, destination="_static"):
406    from zipfile import ZipFile
407    import urllib2
408    url = "https://github.com/Khan/KaTeX/releases/download/%s/katex.zip" % version
409    cache_path = "katex_%s.zip" % version
410    if not os.path.exists(cache_path):
411        try:
412            fd_in = urllib2.urlopen(url)
413            with open(cache_path, "wb") as fd_out:
414                fd_out.write(fd_in.read())
415        finally:
416            fd_in.close()
417    with ZipFile(cache_path) as zip:
418        zip.extractall(destination)
419
[3194371]420def convert_katex():
421    print("=== Preprocess HTML, converting latex to html ===")
422    subprocess.call(["node", "convertKaTex.js", SASVIEW_DOCS])
423
[f4771596]424def convert_mathjax():
425    print("=== Preprocess HTML, converting latex to html ===")
426    subprocess.call(["node", "convertMathJax.js", SASVIEW_DOCS])
427
428def fetch_mathjax():
429    subprocess.call(["npm", "install", "mathjax-node-page"])
430    # TODO: copy fonts from node_modules/mathjax/fonts/HTML-CSS/Tex into static
431
[c2ee2b1]432def rebuild():
[35bf493]433    clean()
[5dd7499]434    setup_source_temp()
[35bf493]435    retrieve_user_docs()
[c22c5e3]436    retrieve_bumps_docs()
[f4771596]437    #fetch_katex(version=KATEX_VERSION, destination=KATEX_PARENT)
438    #fetch_mathjax()
[35bf493]439    apidoc()
440    build()
[3d37fe9]441    if find_executable('latex'):
442        build_pdf()
[3194371]443    #convert_katex()
[f4771596]444    #convert_mathjax()
[c2ee2b1]445
[f4d571b]446    print("=== Done ===")
[c2ee2b1]447
448if __name__ == "__main__":
[9bf64f6]449    rebuild()
Note: See TracBrowser for help on using the repository browser.