99
1010HOME_PATH = os .path .expanduser ("~" )
1111NBCONFIG_DIR_TREE = HOME_PATH + '/.jupyter/nbconfig'
12- CFG_FILE_NAME = 'notebook.json'
13- NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/' + CFG_FILE_NAME
12+ NOTEBOOK_CFG_PATH = NBCONFIG_DIR_TREE + '/notebook.json'
13+
14+ CUSTOM_DIR_TREE = HOME_PATH + '/.jupyter/custom'
15+ NOTEBOOK_CUSTOMJS_PATH = CUSTOM_DIR_TREE + '/custom.js'
1416
1517
1618def patch_cm_cypher_config ():
@@ -33,13 +35,38 @@ def patch_cm_cypher_config():
3335 json .dump (notebook_cfg , file , indent = 2 )
3436
3537
38+ def patch_customjs ():
39+ # Increases time allotted to load nbextensions on large notebooks. Limit is set to 60s and can be increased further.
40+ # Reference: https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/master/docs/source/troubleshooting.md#extensions-not-loading-for-large-notebooks
41+ limit = "60"
42+ increase_requirejs_timeout_prefix = "window.requirejs.config({waitSeconds:"
43+ increase_requirejs_timeout_suffix = "});"
44+ requirejs_timeout_full = increase_requirejs_timeout_prefix + limit + increase_requirejs_timeout_suffix
45+
46+ try :
47+ os .makedirs (CUSTOM_DIR_TREE , exist_ok = True )
48+ with open (NOTEBOOK_CUSTOMJS_PATH , 'r' ) as file :
49+ customjs_content = file .read ()
50+ except (json .decoder .JSONDecodeError , FileNotFoundError ) as e :
51+ customjs_content = ""
52+
53+ if increase_requirejs_timeout_prefix not in customjs_content :
54+ if customjs_content :
55+ customjs_content += "\n "
56+ customjs_content += requirejs_timeout_full
57+ with open (NOTEBOOK_CUSTOMJS_PATH , 'w' ) as file :
58+ file .write (customjs_content )
59+ print (f"Modified nbextensions loader timeout limit to { limit } seconds" )
60+
61+
3662def main ():
3763 parser = argparse .ArgumentParser ()
3864 parser .add_argument ('--notebooks-dir' , default = '' , type = str , help = 'The directory to start Jupyter from.' )
3965
4066 args = parser .parse_args ()
4167
4268 patch_cm_cypher_config ()
69+ patch_customjs ()
4370
4471 kernel_manager_option = "--NotebookApp.kernel_manager_class=notebook.services.kernels.kernelmanager.AsyncMappingKernelManager"
4572 notebooks_dir = '~/notebook/destination/dir' if args .notebooks_dir == '' else args .notebooks_dir
0 commit comments