1313# =-=--
1414
1515import argparse
16+ import glob
1617import os
1718import sys
1819import json
@@ -33,6 +34,18 @@ def system_with_output(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
3334 return proc .returncode , std_out , std_err
3435
3536
37+ def system_checked (cmd , description ):
38+ stat , std_out , std_err = system_with_output (cmd )
39+ if stat != 0 :
40+ print (f"{ description } failed with status code { stat } : { cmd } " , file = sys .stderr )
41+ if std_out :
42+ print (std_out , file = sys .stderr )
43+ if std_err :
44+ print (std_err , file = sys .stderr )
45+ sys .exit (1 )
46+ return std_out
47+
48+
3649deletion_queue = []
3750
3851
@@ -312,7 +325,7 @@ def minifier():
312325
313326 # The navtree indices also need to be loaded in since we're modifying how navbar.js::getScript works.
314327 # This also saves another ~60 files.
315- for nav_tree_index_file in os .listdir ("html" ):
328+ for nav_tree_index_file in sorted ( os .listdir ("html" ) ):
316329 if 'navtreeindex' in nav_tree_index_file :
317330 with open ("html/" + nav_tree_index_file , "r" ) as fp :
318331 navtree_built_data += fp .read () + "\n "
@@ -349,7 +362,7 @@ def build_doxygen(args):
349362 if not os .path .exists ('./Doxyfile-HTML' ):
350363 print ('No Doxyfile found. Are you in the right directory?' )
351364 sys .exit (1 )
352- _ , vers , _ = system_with_output (f"{ doxygen } -V" )
365+ vers = system_checked (f"{ doxygen } -V" , "Querying doxygen version " )
353366
354367 if args .docset :
355368 stat , _ , _ = system_with_output ("doxygen2docset --help" )
@@ -368,25 +381,19 @@ def build_doxygen(args):
368381 shutil .rmtree ("./html/" )
369382 print (f'Building doxygen docs...' )
370383
371- if args .docset :
372- stat , out , err = system_with_output (f"{ doxygen } Doxyfile-Docset" )
373- else :
374- stat , out , err = system_with_output (f"{ doxygen } Doxyfile-HTML" )
375- print (f"Built Doxygen with status code { stat } " )
384+ doxyfile = "Doxyfile-Docset" if args .docset else "Doxyfile-HTML"
385+ system_checked (f"{ doxygen } { doxyfile } " , "Building doxygen docs" )
376386 print ("Output dir is ./html/" )
377- stat , out , err = system_with_output ("cp _static/img/* html/" )
378- print (f"Copied images with status code { stat } " )
387+ system_checked ("cp _static/img/* html/" , "Copying images" )
379388 if args .docset :
380- stat , out , err = system_with_output ("doxygen2docset --doxygen html --docset docset" )
381- print (f"Created docset with status code { stat } " )
389+ system_checked ("doxygen2docset --doxygen html --docset docset" , "Creating docset" )
382390
383391
384392def remove_navtreedata_references ():
385393 """
386394 Remove references to navtreedata.js from HTML files since we've inlined it into navtree.js
387395 """
388- import glob
389- html_files = glob .glob ("html/**/*.html" , recursive = True )
396+ html_files = sorted (glob .glob ("html/**/*.html" , recursive = True ))
390397 count = 0
391398 for html_file in html_files :
392399 with open (html_file , 'r' ) as f :
@@ -406,16 +413,37 @@ def remove_navtreedata_references():
406413 print (f'Removed navtreedata.js references from { count } HTML files' )
407414
408415
416+ def remove_missing_jquery_references ():
417+ if os .path .exists ("html/jquery.js" ):
418+ return
419+
420+ for html_file in sorted (glob .glob ("html/**/*.html" , recursive = True )):
421+ with open (html_file , 'r' ) as f :
422+ content = f .read ()
423+ content = re .sub (
424+ r'<script type="text/javascript" src="(?:\.\./)*jquery\.js"></script>\s*\n' ,
425+ '' ,
426+ content
427+ )
428+ with open (html_file , 'w' ) as f :
429+ f .write (content )
430+
431+
409432def main ():
410433 parser = argparse .ArgumentParser (prog = sys .argv [0 ])
411434 parser .add_argument ("--docset" , action = "store_true" , default = False , help = "Generate Dash docset" )
412435 args = parser .parse_args ()
413436
414437 build_doxygen (args )
415438 print ("Minifying Output" )
439+ # The docset Doxyfile sets GENERATE_TREEVIEW = NO, so navtree.js only exists for HTML builds
416440 if os .path .exists ("html/navtree.js" ):
417441 minifier ()
418442 remove_navtreedata_references ()
443+ elif not args .docset :
444+ print ("html/navtree.js missing after doxygen build, cannot minify output" , file = sys .stderr )
445+ sys .exit (1 )
446+ remove_missing_jquery_references ()
419447 for file in deletion_queue :
420448 file = "./" + file
421449 os .remove (file )
0 commit comments