Changes in docs/sphinx-docs/build_sphinx.py [01f1e17:751f4bd] in sasview
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
docs/sphinx-docs/build_sphinx.py
r01f1e17 r751f4bd 6 6 http://sphinx-doc.org/invocation.html 7 7 """ 8 from __future__ import print_function9 10 8 import subprocess 11 9 import os … … 14 12 import shutil 15 13 import imp 16 17 14 from glob import glob 15 18 16 from distutils.dir_util import copy_tree 19 17 from distutils.util import get_platform … … 57 55 SASMODELS_DEST_BUILDIMG = os.path.join(SASMODELS_DEST_PROLOG, "user", "models", "img") 58 56 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 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 65 #if os.path.exists(SASMODELS_DEST_REF_MODELS): 66 # print "Found models ref folder at ", SASMODELS_DEST_REF_MODELS 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 71 #sys.exit() 59 72 60 73 SPHINX_BUILD = os.path.join(CURRENT_SCRIPT_DIR, "build") … … 75 88 s=open(filename).read() 76 89 if old_string in s: 77 print ('Changing "{old_string}" to "{new_string}"'.format(**locals()))90 print 'Changing "{old_string}" to "{new_string}"'.format(**locals()) 78 91 s=s.replace(old_string, new_string) 79 92 f=open(filename, 'w') … … 82 95 f.close() 83 96 else: 84 print ('No occurences of "{old_string}" found.'.format(**locals()))97 print 'No occurences of "{old_string}" found.'.format(**locals()) 85 98 86 99 def _remove_dir(dir_path): 87 100 """Removes the given directory.""" 88 101 if os.path.isdir(dir_path): 89 print ("Removing \"%s\"... " % dir_path)102 print "Removing \"%s\"... " % dir_path 90 103 shutil.rmtree(dir_path) 91 104 … … 94 107 Clean the sphinx build directory. 95 108 """ 96 print ("=== Cleaning Sphinx Build ===")109 print "=== Cleaning Sphinx Build ===" 97 110 _remove_dir(SASVIEW_DOCS) 98 111 _remove_dir(SPHINX_BUILD) … … 107 120 Copy the source toctrees to new folder for assembling the sphinx-docs 108 121 """ 109 print ("=== Copying Source toctrees ===")122 print "=== Copying Source toctrees ===" 110 123 if os.path.exists(SASVIEW_TOC_SOURCE): 111 print ("Found docs folder at", SASVIEW_TOC_SOURCE)124 print "Found docs folder at ", SASVIEW_TOC_SOURCE 112 125 shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE) 113 126 … … 128 141 so that Sphinx may pick it up when generating the documentation. 129 142 """ 130 print ("=== Retrieve User Docs ===")143 print "=== Retrieve User Docs ===" 131 144 132 145 # Copy documentation files from their "source" to their "destination". … … 135 148 136 149 docs = os.path.abspath(os.path.join(root, dirname)) 137 print ("Found docs folder at \"%s\"." % docs)150 print "Found docs folder at \"%s\"." % docs 138 151 139 152 dest_dir_part = os.path.dirname(os.path.relpath(docs, SASVIEW_SRC)) … … 145 158 146 159 # Now pickup testdata_help.rst 147 print("=== Including Test Data Docs ===") 160 # print os.path.abspath(SASVIEW_TEST) 161 # print os.path.abspath(SPHINX_SOURCE_TEST) 162 print "=== Including Test Data Docs ===" 148 163 if os.path.exists(SASVIEW_TEST): 149 print ("Found docs folder at", SASVIEW_TEST)164 print "Found docs folder at ", SASVIEW_TEST 150 165 shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST) 151 166 152 print ("=== And the Sasmodels Docs ===")167 print "=== And the Sasmodels Docs ===" 153 168 # Make sure we have the relevant images for the new sasmodels documentation 154 169 # First(!) we'll make a local reference copy for SasView (/new-models will be cleaned each build) 155 170 if os.path.exists(SASMODELS_SOURCE_IMG): 156 print ("Found img folder SASMODELS_SOURCE_IMG at", SASMODELS_SOURCE_IMG)171 print "Found img folder SASMODELS_SOURCE_IMG at ", SASMODELS_SOURCE_IMG 157 172 if not os.path.exists(SASMODELS_DEST_IMG): 158 print ("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG)173 print "Missing docs folder SASMODELS_DEST_IMG at ", SASMODELS_DEST_IMG 159 174 os.makedirs(SASMODELS_DEST_IMG) 160 print("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG) 161 else: 162 print("Found img folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG) 163 print("Copying sasmodels model image files...") 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..." 164 178 for files in os.listdir(SASMODELS_SOURCE_IMG): 165 179 fromhere=os.path.join(SASMODELS_SOURCE_IMG,files) 166 180 tohere=os.path.join(SASMODELS_DEST_IMG,files) 167 181 shutil.copy(fromhere,tohere) 168 else: 169 print("no source directory",SASMODELS_SOURCE_IMG,"was found") 182 else: print "cannot find SASMODELS_SOURCE_IMG", SASMODELS_SOURCE_IMG 170 183 171 184 if os.path.exists(SASMODELS_SOURCE_AUTOIMG): 172 print ("Found img folder SASMODELS_SOURCE_AUTOIMG at", SASMODELS_SOURCE_AUTOIMG)185 print "Found img folder SASMODELS_SOURCE_AUTOIMG at ", SASMODELS_SOURCE_AUTOIMG 173 186 if not os.path.exists(SASMODELS_DEST_IMG): 174 print ("Missing docs folder SASMODELS_DEST_IMG at", SASMODELS_DEST_IMG)187 print "Missing docs folder SASMODELS_DEST_IMG at ", SASMODELS_DEST_IMG 175 188 os.makedirs(SASMODELS_DEST_BUILDIMG) 176 print ("created SASMODELS_DEST_BUILDIMG at", SASMODELS_DEST_BUILDIMG)177 print ("Copying sasmodels model auto-generated image files...")189 print "created SASMODELS_DEST_BUILDIMG at ", SASMODELS_DEST_BUILDIMG 190 print "Copying sasmodels model auto-generated image files..." 178 191 for files in os.listdir(SASMODELS_SOURCE_AUTOIMG): 179 192 fromhere=os.path.join(SASMODELS_SOURCE_AUTOIMG,files) 180 193 tohere=os.path.join(SASMODELS_DEST_IMG,files) 181 194 shutil.copy(fromhere,tohere) 182 else: 183 print("no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found") 195 else: print "no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found" 184 196 185 197 # And the rst prolog with the unit substitutions 186 198 if os.path.exists(SASMODELS_SOURCE_PROLOG): 187 print ("Found prolog folder SASMODELS_SOURCE_PROLOG at", SASMODELS_SOURCE_PROLOG)199 print "Found prolog folder SASMODELS_SOURCE_PROLOG at ", SASMODELS_SOURCE_PROLOG 188 200 if os.path.exists(SASMODELS_DEST_PROLOG): 189 print ("Found docs folder SASMODELS_DEST_PROLOG at", SASMODELS_DEST_PROLOG)190 print ("Copying sasmodels rst_prolog file...")201 print "Found docs folder SASMODELS_DEST_PROLOG at ", SASMODELS_DEST_PROLOG 202 print "Copying sasmodels rst_prolog file..." 191 203 for files in os.listdir(SASMODELS_SOURCE_PROLOG): 192 204 if files.startswith("rst"): … … 194 206 tohere=os.path.join(SASMODELS_DEST_PROLOG,files) 195 207 shutil.copy(fromhere,tohere) 196 else:197 print("no source directory",SASMODELS_SOURCE_PROLOG, "was found")198 208 199 209 if os.path.exists(SASMODELS_SOURCE_GPU): 200 print ("Found docs folder SASMODELS_SOURCE_GPU at", SASMODELS_SOURCE_GPU)210 print "Found docs folder SASMODELS_SOURCE_GPU at ", SASMODELS_SOURCE_GPU 201 211 if os.path.exists(SPHINX_SOURCE_USER): 202 print ("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER)203 print ("Copying sasmodels gpu files...")212 print "Found docs folder SPHINX_SOURCE_USER at ", SPHINX_SOURCE_USER 213 print "Copying sasmodels gpu files..." 204 214 for files in os.listdir(SASMODELS_SOURCE_GPU): 205 215 if files.endswith(".rst"): … … 207 217 tohere=os.path.join(SPHINX_SOURCE_USER,files) 208 218 shutil.copy(fromhere,tohere) 209 else:210 print("no source directory",SASMODELS_SOURCE_GPU,"was found")211 219 212 220 if os.path.exists(SASMODELS_SOURCE_SESANS): 213 print ("Found docs folder SASMODELS_SOURCE_SESANS at", SASMODELS_SOURCE_SESANS)221 print "Found docs folder SASMODELS_SOURCE_SESANS at ", SASMODELS_SOURCE_SESANS 214 222 if os.path.exists(SPHINX_SOURCE_USER): 215 print ("Found docs folder SPHINX_SOURCE_USER at", SPHINX_SOURCE_USER)216 print ("Copying sasmodels sesans files...")223 print "Found docs folder SPHINX_SOURCE_USER at ", SPHINX_SOURCE_USER 224 print "Copying sasmodels sesans files..." 217 225 for files in os.listdir(SASMODELS_SOURCE_SESANS): 218 226 if files.endswith(".rst"): … … 220 228 tohere=os.path.join(SPHINX_SOURCE_USER,files) 221 229 shutil.copy(fromhere,tohere) 222 else:223 print("no source directory",SASMODELS_SOURCE_SESANS,"was found")224 230 225 231 if os.path.exists(SASMODELS_SOURCE_MAGNETISM): 226 print ("Found docs folder SASMODELS_SOURCE_MAGNETISM at", SASMODELS_SOURCE_MAGNETISM)232 print "Found docs folder SASMODELS_SOURCE_MAGNETISM at ", SASMODELS_SOURCE_MAGNETISM 227 233 if os.path.exists(SASMODELS_DEST_REF_MODELS): 228 print ("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS)229 print ("Copying sasmodels model toctree files...")234 print "Found docs folder SASMODELS_DEST_REF_MODELS at ", SASMODELS_DEST_REF_MODELS 235 print "Copying sasmodels model toctree files..." 230 236 for files in os.listdir(SASMODELS_SOURCE_MAGNETISM): 231 237 if files.endswith(".rst"): … … 233 239 tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 234 240 shutil.copy(fromhere,tohere) 235 else:236 print("no source directory",SASMODELS_SOURCE_MAGNETISM,"was found")237 241 238 242 if os.path.exists(SASMODELS_SOURCE_MAGIMG): 239 print ("Found img folder SASMODELS_SOURCE_MAGIMG at", SASMODELS_SOURCE_MAGIMG)243 print "Found img folder SASMODELS_SOURCE_MAGIMG at ", SASMODELS_SOURCE_MAGIMG 240 244 if not os.path.exists(SASMODELS_DEST_MAGIMG): 241 print ("Missing img folder SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG)245 print "Missing img folder SASMODELS_DEST_MAGIMG at ", SASMODELS_DEST_MAGIMG 242 246 os.makedirs(SASMODELS_DEST_MAGIMG) 243 print ("created SASMODELS_DEST_MAGIMG at", SASMODELS_DEST_MAGIMG)244 print ("Copying sasmodels mag image files...")247 print "created SASMODELS_DEST_MAGIMG at ", SASMODELS_DEST_MAGIMG 248 print "Copying sasmodels mag image files..." 245 249 for files in os.listdir(SASMODELS_SOURCE_MAGIMG): 246 250 fromhere=os.path.join(SASMODELS_SOURCE_MAGIMG,files) 247 251 tohere=os.path.join(SASMODELS_DEST_MAGIMG,files) 248 252 shutil.copy(fromhere,tohere) 249 else: 250 print("no source directory",SASMODELS_SOURCE_MAGIMG ,"was found") 253 else: print "no source directory",SASMODELS_SOURCE_MAGIMG ,"was found" 251 254 252 255 if os.path.exists(SASMODELS_SOURCE_SESANSIMG): 253 print ("Found img folder SASMODELS_SOURCE_SESANSIMG at", SASMODELS_SOURCE_SESANSIMG)256 print "Found img folder SASMODELS_SOURCE_SESANSIMG at ", SASMODELS_SOURCE_SESANSIMG 254 257 if not os.path.exists(SASMODELS_DEST_SESANSIMG): 255 print ("Missing img folder SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG)258 print "Missing img folder SASMODELS_DEST_SESANSIMG at ", SASMODELS_DEST_SESANSIMG 256 259 os.makedirs(SASMODELS_DEST_SESANSIMG) 257 print ("created SASMODELS_DEST_SESANSIMG at", SASMODELS_DEST_SESANSIMG)258 print ("Copying sasmodels sesans image files...")260 print "created SASMODELS_DEST_SESANSIMG at ", SASMODELS_DEST_SESANSIMG 261 print "Copying sasmodels sesans image files..." 259 262 for files in os.listdir(SASMODELS_SOURCE_SESANSIMG): 260 263 fromhere=os.path.join(SASMODELS_SOURCE_SESANSIMG,files) 261 264 tohere=os.path.join(SASMODELS_DEST_SESANSIMG,files) 262 265 shutil.copy(fromhere,tohere) 263 else: 264 print("no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found") 266 else: print "no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found" 265 267 266 268 if os.path.exists(SASMODELS_SOURCE_REF_MODELS): 267 print ("Found docs folder SASMODELS_SOURCE_REF_MODELS at", SASMODELS_SOURCE_REF_MODELS)269 print "Found docs folder SASMODELS_SOURCE_REF_MODELS at ", SASMODELS_SOURCE_REF_MODELS 268 270 if os.path.exists(SASMODELS_DEST_REF_MODELS): 269 print ("Found docs folder SASMODELS_DEST_REF_MODELS at", SASMODELS_DEST_REF_MODELS)270 print ("Copying sasmodels model toctree files...")271 print "Found docs folder SASMODELS_DEST_REF_MODELS at ", SASMODELS_DEST_REF_MODELS 272 print "Copying sasmodels model toctree files..." 271 273 for files in os.listdir(SASMODELS_SOURCE_REF_MODELS): 272 274 if files.endswith(".rst"): … … 274 276 tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 275 277 shutil.copy(fromhere,tohere) 276 # But need to change the path to the model docs in the tocs 277 for files in os.listdir(SASMODELS_DEST_REF_MODELS): 278 # print files 279 if files.startswith("shape"): 280 print("Changing toc paths in", files) 281 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 282 if files.startswith("sphere"): 283 print("Changing toc paths in", files) 284 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 285 if files.startswith("custom"): 286 print("Changing toc paths in", files) 287 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 288 if files.startswith("structure"): 289 print("Changing toc paths in", files) 290 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 291 else: 292 print("no source directory",SASMODELS_SOURCE_REF_MODELS," was found") 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/") 293 293 294 294 if os.path.exists(SASMODELS_SOURCE_MODELS): 295 print ("Found docs folder SASMODELS_SOURCE_MODELS at", SASMODELS_SOURCE_MODELS)295 print "Found docs folder SASMODELS_SOURCE_MODELS at ", SASMODELS_SOURCE_MODELS 296 296 if os.path.exists(SASMODELS_DEST_MODELS): 297 print ("Found docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS)298 print ("Copying sasmodels model files...")297 print "Found docs folder SASMODELS_DEST_MODELS at ", SASMODELS_DEST_MODELS 298 print "Copying sasmodels model files..." 299 299 for files in os.listdir(SASMODELS_SOURCE_MODELS): 300 300 if files.endswith(".rst"): … … 303 303 shutil.copy(fromhere,tohere) 304 304 else: 305 print ("Missing docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS)305 print "Missing docs folder SASMODELS_DEST_MODELS at ", SASMODELS_DEST_MODELS 306 306 os.makedirs(SASMODELS_DEST_MODELS) 307 307 if not os.path.exists(SASMODELS_DEST_BUILDIMG): 308 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...")309 print "Created docs folder SASMODELS_DEST_MODELS at ", SASMODELS_DEST_MODELS 310 print "Copying model files for build..." 311 311 for files in os.listdir(SASMODELS_SOURCE_MODELS): 312 312 if files.endswith(".rst"): … … 315 315 shutil.copy(fromhere,tohere) 316 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...")317 print "Copying image files for build..." 318 318 for files in os.listdir(SASMODELS_DEST_IMG): 319 319 fromhere=os.path.join(SASMODELS_DEST_IMG,files) 320 320 tohere=os.path.join(SASMODELS_DEST_BUILDIMG,files) 321 321 shutil.copy(fromhere,tohere) 322 else:323 print("no source directory",SASMODELS_SOURCE_MODELS,"was found.")324 print("!!!!NO MODEL DOCS WILL BE BUILT!!!!")325 322 326 323 … … 330 327 """ 331 328 if os.path.exists(BUMPS_DOCS): 332 print ("=== Retrieve BUMPS Docs ===")329 print "=== Retrieve BUMPS Docs ===" 333 330 filenames = [os.path.join(BUMPS_DOCS, "optimizer.rst")] 334 331 filenames += glob(os.path.join(BUMPS_DOCS, "dream-*.png")) 335 332 filenames += glob(os.path.join(BUMPS_DOCS, "fit-*.png")) 336 333 for f in filenames: 337 print ("Copying file", f)334 print "Copying file", f 338 335 shutil.copy(f, BUMPS_TARGET) 339 336 else: 340 print(""" 341 ======= Error ======= 342 missing directory %s 337 print """ 338 *** Error *** missing directory %s 343 339 The documentation will not include the optimizer selection section. 344 340 Checkout the bumps source tree and rebuild the docs. 345 """ % BUMPS_DOCS) 341 342 343 """ % BUMPS_DOCS 346 344 347 345 def apidoc(): … … 350 348 in the SasView build directory. 351 349 """ 352 print ("=== Generate API Rest Files ===")350 print "=== Generate API Rest Files ===" 353 351 354 352 # Clean directory before generating a new version. … … 364 362 Runs sphinx-build. Reads in all .rst files and spits out the final html. 365 363 """ 366 print ("=== Build HTML Docs from Rest Files ===")364 print "=== Build HTML Docs from Rest Files ===" 367 365 subprocess.call(["sphinx-build", 368 366 "-b", "html", # Builder name. TODO: accept as arg to setup.py. … … 371 369 os.path.join(SPHINX_BUILD, "html")]) 372 370 373 print ("=== Copy HTML Docs to Build Directory ===")371 print "=== Copy HTML Docs to Build Directory ===" 374 372 html = os.path.join(SPHINX_BUILD, "html") 375 373 copy_tree(html, SASVIEW_DOCS) … … 383 381 build() 384 382 385 print ("=== Done ===")383 print "=== Done ===" 386 384 387 385 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.