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