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