Changeset 90d9cd3 in sasview
- Timestamp:
- Jun 16, 2017 10:15:17 AM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 3194371
- Parents:
- 28c4a3d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
docs/sphinx-docs/build_sphinx.py
r9d566b2 r90d9cd3 21 21 from os import listdir 22 22 23 platform = '.%s-%s'%(get_platform(), 23 platform = '.%s-%s'%(get_platform(),sys.version[:3]) 24 24 25 25 CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) … … 46 46 SASMODELS_SOURCE_MODELS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model") 47 47 SASMODELS_SOURCE_IMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model", "img") 48 SASMODELS_SOURCE_AUTOIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "_build", "html", 48 SASMODELS_SOURCE_AUTOIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "_build", "html","_images") 49 49 ## Don't do assemble-in-place 50 50 ## Assemble the docs in a temporary folder … … 66 66 SPHINX_SOURCE_TEST = os.path.join(SPHINX_SOURCE, "test") 67 67 SPHINX_SOURCE_USER = os.path.join(SPHINX_SOURCE, "user") 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/releases71 68 72 69 BUMPS_DOCS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", … … 76 73 def inplace_change(filename, old_string, new_string): 77 74 # Thanks to http://stackoverflow.com/questions/4128144/replace-string-within-file-contents 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()))75 s=open(filename).read() 76 if old_string in s: 77 print('Changing "{old_string}" to "{new_string}"'.format(**locals())) 78 s=s.replace(old_string, new_string) 79 f=open(filename, 'w') 80 f.write(s) 81 f.flush() 82 f.close() 83 else: 84 print('No occurences of "{old_string}" found.'.format(**locals())) 88 85 89 86 def _remove_dir(dir_path): … … 101 98 _remove_dir(SPHINX_BUILD) 102 99 _remove_dir(SPHINX_SOURCE) 103 _remove_dir(KATEX_PATH)104 100 #_remove_dir(SPHINX_SOURCE_GUIFRAME) 105 101 #_remove_dir(SPHINX_SOURCE_MODELS) … … 113 109 print("=== Copying Source toctrees ===") 114 110 if os.path.exists(SASVIEW_TOC_SOURCE): 115 116 111 print("Found docs folder at", SASVIEW_TOC_SOURCE) 112 shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE) 117 113 118 114 def retrieve_user_docs(): … … 151 147 print("=== Including Test Data Docs ===") 152 148 if os.path.exists(SASVIEW_TEST): 153 154 149 print("Found docs folder at", SASVIEW_TEST) 150 shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST) 155 151 156 152 print("=== And the Sasmodels Docs ===") 157 153 # Make sure we have the relevant images for the new sasmodels documentation 158 # First(!) we'll make a local reference copy for SasView 159 # (/new-models will be cleaned each build) 154 # First(!) we'll make a local reference copy for SasView (/new-models will be cleaned each build) 160 155 if os.path.exists(SASMODELS_SOURCE_IMG): 161 156 print("Found img folder SASMODELS_SOURCE_IMG at", SASMODELS_SOURCE_IMG) … … 168 163 print("Copying sasmodels model image files...") 169 164 for files in os.listdir(SASMODELS_SOURCE_IMG): 170 fromhere = os.path.join(SASMODELS_SOURCE_IMG,files)171 tohere = os.path.join(SASMODELS_DEST_IMG,files)172 shutil.copy(fromhere, 173 else: 174 print("no source directory", SASMODELS_SOURCE_IMG,"was found")165 fromhere=os.path.join(SASMODELS_SOURCE_IMG,files) 166 tohere=os.path.join(SASMODELS_DEST_IMG,files) 167 shutil.copy(fromhere,tohere) 168 else: 169 print("no source directory",SASMODELS_SOURCE_IMG,"was found") 175 170 176 171 if os.path.exists(SASMODELS_SOURCE_AUTOIMG): … … 182 177 print("Copying sasmodels model auto-generated image files...") 183 178 for files in os.listdir(SASMODELS_SOURCE_AUTOIMG): 184 fromhere = os.path.join(SASMODELS_SOURCE_AUTOIMG,files)185 tohere = os.path.join(SASMODELS_DEST_IMG,files)186 shutil.copy(fromhere, 187 else: 188 print("no source directory", SASMODELS_SOURCE_AUTOIMG,"was found")179 fromhere=os.path.join(SASMODELS_SOURCE_AUTOIMG,files) 180 tohere=os.path.join(SASMODELS_DEST_IMG,files) 181 shutil.copy(fromhere,tohere) 182 else: 183 print("no source directory",SASMODELS_SOURCE_AUTOIMG ,"was found") 189 184 190 185 # And the rst prolog with the unit substitutions … … 196 191 for files in os.listdir(SASMODELS_SOURCE_PROLOG): 197 192 if files.startswith("rst"): 198 fromhere = os.path.join(SASMODELS_SOURCE_PROLOG,files)199 tohere = os.path.join(SASMODELS_DEST_PROLOG,files)200 shutil.copy(fromhere, 201 else: 202 print("no source directory", 193 fromhere=os.path.join(SASMODELS_SOURCE_PROLOG,files) 194 tohere=os.path.join(SASMODELS_DEST_PROLOG,files) 195 shutil.copy(fromhere,tohere) 196 else: 197 print("no source directory",SASMODELS_SOURCE_PROLOG, "was found") 203 198 204 199 if os.path.exists(SASMODELS_SOURCE_GPU): … … 209 204 for files in os.listdir(SASMODELS_SOURCE_GPU): 210 205 if files.endswith(".rst"): 211 fromhere = os.path.join(SASMODELS_SOURCE_GPU,files)212 tohere = os.path.join(SPHINX_SOURCE_USER,files)213 shutil.copy(fromhere, 214 else: 215 print("no source directory", SASMODELS_SOURCE_GPU,"was found")206 fromhere=os.path.join(SASMODELS_SOURCE_GPU,files) 207 tohere=os.path.join(SPHINX_SOURCE_USER,files) 208 shutil.copy(fromhere,tohere) 209 else: 210 print("no source directory",SASMODELS_SOURCE_GPU,"was found") 216 211 217 212 if os.path.exists(SASMODELS_SOURCE_SESANS): … … 222 217 for files in os.listdir(SASMODELS_SOURCE_SESANS): 223 218 if files.endswith(".rst"): 224 fromhere = os.path.join(SASMODELS_SOURCE_SESANS,files)225 tohere = os.path.join(SPHINX_SOURCE_USER,files)226 shutil.copy(fromhere, 227 else: 228 print("no source directory", SASMODELS_SOURCE_SESANS,"was found")219 fromhere=os.path.join(SASMODELS_SOURCE_SESANS,files) 220 tohere=os.path.join(SPHINX_SOURCE_USER,files) 221 shutil.copy(fromhere,tohere) 222 else: 223 print("no source directory",SASMODELS_SOURCE_SESANS,"was found") 229 224 230 225 if os.path.exists(SASMODELS_SOURCE_MAGNETISM): … … 235 230 for files in os.listdir(SASMODELS_SOURCE_MAGNETISM): 236 231 if files.endswith(".rst"): 237 fromhere = os.path.join(SASMODELS_SOURCE_MAGNETISM,files)238 tohere = os.path.join(SASMODELS_DEST_REF_MODELS,files)239 shutil.copy(fromhere, 240 else: 241 print("no source directory", SASMODELS_SOURCE_MAGNETISM,"was found")232 fromhere=os.path.join(SASMODELS_SOURCE_MAGNETISM,files) 233 tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 234 shutil.copy(fromhere,tohere) 235 else: 236 print("no source directory",SASMODELS_SOURCE_MAGNETISM,"was found") 242 237 243 238 if os.path.exists(SASMODELS_SOURCE_MAGIMG): … … 249 244 print("Copying sasmodels mag image files...") 250 245 for files in os.listdir(SASMODELS_SOURCE_MAGIMG): 251 fromhere = os.path.join(SASMODELS_SOURCE_MAGIMG,files)252 tohere = os.path.join(SASMODELS_DEST_MAGIMG,files)253 shutil.copy(fromhere, 254 else: 255 print("no source directory", SASMODELS_SOURCE_MAGIMG,"was found")246 fromhere=os.path.join(SASMODELS_SOURCE_MAGIMG,files) 247 tohere=os.path.join(SASMODELS_DEST_MAGIMG,files) 248 shutil.copy(fromhere,tohere) 249 else: 250 print("no source directory",SASMODELS_SOURCE_MAGIMG ,"was found") 256 251 257 252 if os.path.exists(SASMODELS_SOURCE_SESANSIMG): … … 263 258 print("Copying sasmodels sesans image files...") 264 259 for files in os.listdir(SASMODELS_SOURCE_SESANSIMG): 265 fromhere = os.path.join(SASMODELS_SOURCE_SESANSIMG,files)266 tohere = os.path.join(SASMODELS_DEST_SESANSIMG,files)267 shutil.copy(fromhere, 268 else: 269 print("no source directory", SASMODELS_SOURCE_SESANSIMG,"was found")260 fromhere=os.path.join(SASMODELS_SOURCE_SESANSIMG,files) 261 tohere=os.path.join(SASMODELS_DEST_SESANSIMG,files) 262 shutil.copy(fromhere,tohere) 263 else: 264 print("no source directory",SASMODELS_SOURCE_SESANSIMG ,"was found") 270 265 271 266 if os.path.exists(SASMODELS_SOURCE_REF_MODELS): … … 276 271 for files in os.listdir(SASMODELS_SOURCE_REF_MODELS): 277 272 if files.endswith(".rst"): 278 fromhere = os.path.join(SASMODELS_SOURCE_REF_MODELS,files)279 tohere = os.path.join(SASMODELS_DEST_REF_MODELS,files)280 shutil.copy(fromhere, 273 fromhere=os.path.join(SASMODELS_SOURCE_REF_MODELS,files) 274 tohere=os.path.join(SASMODELS_DEST_REF_MODELS,files) 275 shutil.copy(fromhere,tohere) 281 276 # But need to change the path to the model docs in the tocs 282 277 for files in os.listdir(SASMODELS_DEST_REF_MODELS): … … 284 279 if files.startswith("shape"): 285 280 print("Changing toc paths in", files) 286 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, 281 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 287 282 if files.startswith("sphere"): 288 283 print("Changing toc paths in", files) 289 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, 284 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 290 285 if files.startswith("custom"): 291 286 print("Changing toc paths in", files) 292 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, 287 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS,files), "../../model/", "models/") 293 288 if files.startswith("structure"): 294 289 print("Changing toc paths in", files) 295 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, 296 else: 297 print("no source directory", SASMODELS_SOURCE_REF_MODELS," was found")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") 298 293 299 294 if os.path.exists(SASMODELS_SOURCE_MODELS): … … 304 299 for files in os.listdir(SASMODELS_SOURCE_MODELS): 305 300 if files.endswith(".rst"): 306 fromhere = os.path.join(SASMODELS_SOURCE_MODELS,files)307 tohere = os.path.join(SASMODELS_DEST_MODELS,files)308 shutil.copy(fromhere, 301 fromhere=os.path.join(SASMODELS_SOURCE_MODELS,files) 302 tohere=os.path.join(SASMODELS_DEST_MODELS,files) 303 shutil.copy(fromhere,tohere) 309 304 else: 310 305 print("Missing docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS) … … 316 311 for files in os.listdir(SASMODELS_SOURCE_MODELS): 317 312 if files.endswith(".rst"): 318 fromhere = os.path.join(SASMODELS_SOURCE_MODELS,files)319 tohere = os.path.join(SASMODELS_DEST_MODELS,files)320 shutil.copy(fromhere, 313 fromhere=os.path.join(SASMODELS_SOURCE_MODELS,files) 314 tohere=os.path.join(SASMODELS_DEST_MODELS,files) 315 shutil.copy(fromhere,tohere) 321 316 # No choice but to do this because model files are all coded for images in /models/img 322 317 print("Copying image files for build...") 323 318 for files in os.listdir(SASMODELS_DEST_IMG): 324 fromhere = os.path.join(SASMODELS_DEST_IMG,files)325 tohere = os.path.join(SASMODELS_DEST_BUILDIMG,files)326 shutil.copy(fromhere, 327 else: 328 print("no source directory", SASMODELS_SOURCE_MODELS,"was found.")319 fromhere=os.path.join(SASMODELS_DEST_IMG,files) 320 tohere=os.path.join(SASMODELS_DEST_BUILDIMG,files) 321 shutil.copy(fromhere,tohere) 322 else: 323 print("no source directory",SASMODELS_SOURCE_MODELS,"was found.") 329 324 print("!!!!NO MODEL DOCS WILL BE BUILT!!!!") 330 331 325 332 326 def fetch_katex(version, destination="_static"): … … 345 339 zip.extractall(destination) 346 340 347 348 341 def retrieve_bumps_docs(): 349 342 """
Note: See TracChangeset
for help on using the changeset viewer.