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