def install_extensions(enable=True, user=False): """Register ipyparallel clusters tab as notebook extensions Toggle with enable=True/False. """ import notebook from ipyparallel.util import _v if _v(notebook.__version__) < _v('4.2'): return _install_extension_nb41(enable) from notebook.nbextensions import ( disable_nbextension, enable_nbextension, install_nbextension_python, ) from notebook.serverextensions import toggle_serverextension_python toggle_serverextension_python('ipyparallel', user=user) install_nbextension_python('ipyparallel', user=user) if enable: enable_nbextension('tree', 'ipyparallel/main', user=user) else: disable_nbextension('tree', 'ipyparallel/main')
def activate_student_exam(self, sys_prefix=True, user=False): print(f'Activate student exam mode with sys_prefix = {sys_prefix} and user = {user}') # Enable server extensions self.activate_student(sys_prefix=sys_prefix, user=user) enable_nbextension(require='exam_view/main', section='notebook', sys_prefix=sys_prefix, user=user) enable_nbextension(require='restricted_tree/main', section='tree', sys_prefix=sys_prefix, user=user)
def test_check_enable(): enable_nbextension(section='notebook', require='notebook_magiclight/index') config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig') cm = BaseJSONConfigManager(config_dir=config_dir) enabled = cm.get('notebook').get('load_extensions', {}).get('notebook_magiclight/index', False) assert enabled
def activate_teacher(self, sys_prefix=True, user=False): print( f"Activate teacher mode with sys_prefix = {sys_prefix} and user = {user}" ) # Enable server extensions self.enable_serverextension_py("nbgrader", sys_prefix=sys_prefix, user=user) self.disable_serverextension("nbgrader.server_extensions.formgrader") self.disable_serverextension( "nbgrader.server_extensions.assignment_list") self.enable_serverextension_py("e2xgrader", sys_prefix=sys_prefix, user=user) # Install nbgrader nbextensions self.install_nbextensions("nbgrader", sys_prefix=sys_prefix, user=user) enable_nbextension_python("nbgrader", sys_prefix=sys_prefix, user=user) disable_nbextension( require="create_assignment/main", section="notebook", sys_prefix=sys_prefix, user=user, ) # Install e2xgrader nbextensions self.install_nbextensions("e2xgrader", sys_prefix=sys_prefix, user=user) enable_nbextension( require="extra_cells/main", section="notebook", sys_prefix=sys_prefix, user=user, ) enable_nbextension( require="create_assignment/main", section="notebook", sys_prefix=sys_prefix, user=user, ) enable_nbextension(require="taskcreator/main", section="tree", sys_prefix=sys_prefix, user=user) enable_nbextension( require="templatebar/main", section="notebook", sys_prefix=sys_prefix, user=user, ) enable_nbextension( require="taskeditor/main", section="notebook", sys_prefix=sys_prefix, user=user, )
def install_nbextension(cmd, link=False): from notebook.nbextensions import (install_nbextension_python, enable_nbextension) install_nbextension_python("geonotebook", overwrite=True, sys_prefix=True, symlink=link) enable_nbextension("notebook", "geonotebook/index", sys_prefix=True)
def test_nbextension_enable(self): with TemporaryDirectory() as d: f = u'ƒ.js' src = pjoin(d, f) touch(src) install_nbextension(src, user=True) enable_nbextension(section='notebook', require=u'ƒ') config_dir = os.path.join(_get_config_dir(user=True), 'nbconfig') cm = BaseJSONConfigManager(config_dir=config_dir) enabled = cm.get('notebook').get('load_extensions', {}).get(u'ƒ', False) assert enabled
def run(self): src_dir = os.path.join(repo_root, 'odps', 'static', 'ui', 'target') dest_dir = os.path.join(jupyter_data_dir(), 'nbextensions', 'pyodps') if os.path.exists(dest_dir): shutil.rmtree(dest_dir) if not os.path.exists(dest_dir): os.makedirs(dest_dir) recursive_overwrite(src_dir, dest_dir) try: from notebook.nbextensions import enable_nbextension except ImportError: return enable_nbextension('notebook', 'pyodps/main')
def install(args): # Write kernel spec in a temporary directory user = False if "user" in args: user = args.user print("Installing jupyter kernel spec") install_kernel_spec('etc/jupyter/', kernel_name='gap-4', user=user) print("Installing nbextension for syntax hilighting") install_nbextension('etc/gap-mode', overwrite=True, user=user) enable_nbextension( 'notebook', 'gap-mode/main', )
def run(self): from notebook.nbextensions import enable_nbextension # run from distutils install _install.run(self) #install kernel specs with TemporaryDirectory() as td: os.chmod(td, 0o755) # Starts off as 700, not user readable with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) print('Installing IPython kernel spec') install_kernel_spec(td, 'Singular', user=self.user, replace=True) # enable codemirror notebook extension enable_nbextension('notebook', 'singular-mode/main')
def activate_student_exam(self, sys_prefix=True, user=False): print( f"Activate student exam mode with sys_prefix = {sys_prefix} and user = {user}" ) # Enable server extensions self.activate_student(sys_prefix=sys_prefix, user=user) enable_nbextension( require="exam_view/main", section="notebook", sys_prefix=sys_prefix, user=user, ) enable_nbextension( require="restricted_tree/main", section="tree", sys_prefix=sys_prefix, user=user, )
def install_extensions(enable=True): """Register ipyparallel clusters tab as notebook extensions Toggle with enable=True/False. """ from distutils.version import LooseVersion as V import notebook if V(notebook.__version__) < V('4.2'): return _install_extension_nb41(enable) from notebook.nbextensions import install_nbextension_python, enable_nbextension, disable_nbextension from notebook.serverextensions import toggle_serverextension_python toggle_serverextension_python('ipyparallel.nbextension') install_nbextension_python('ipyparallel') if enable: enable_nbextension('tree', 'ipyparallel/main') else: disable_nbextension('tree', 'ipyparallel/main')
def activate_teacher(self, sys_prefix=True, user=False): print(f'Activate teacher mode with sys_prefix = {sys_prefix} and user = {user}') # Enable server extensions self.enable_serverextension_py('nbgrader', sys_prefix=sys_prefix, user=user) self.disable_serverextension('nbgrader.server_extensions.formgrader') self.disable_serverextension('nbgrader.server_extensions.assignment_list') self.enable_serverextension_py('e2xgrader', sys_prefix=sys_prefix, user=user) # Install nbgrader nbextensions self.install_nbextensions('nbgrader', sys_prefix=sys_prefix, user=user) enable_nbextension_python('nbgrader', sys_prefix=sys_prefix, user=user) disable_nbextension(require='create_assignment/main', section='notebook', sys_prefix=sys_prefix, user=user) # Install e2xgrader nbextensions self.install_nbextensions('e2xgrader', sys_prefix=sys_prefix, user=user) enable_nbextension(require='extra_cells/main', section='notebook', sys_prefix=sys_prefix, user=user) enable_nbextension(require='create_assignment/main', section='notebook', sys_prefix=sys_prefix, user=user)
def install_kernel(c): # Write kernel spec in a temporary directory user = False opt = c.command_options if 'install' in opt: if 'user' in opt['install']: user = True c.announce("Installing jupyter kernel spec") with TemporaryDirectory() as td: with open(os.path.join(td, 'kernel.json'), 'w') as f: json.dump(kernel_json, f, sort_keys=True) install_kernel_spec(td, kernel_name='gap-wrapper', user=user) c.announce("Installing nbextension for syntax hilighting") install_nbextension('jupyter_kernel_gap/resources/gap-mode', overwrite=True, user=user) enable_nbextension( 'notebook', 'gap-mode/main', )
def run_nbextension_install(develop): from notebook.nbextensions import install_nbextension_python, enable_nbextension_python, install_nbextension from notebook.serverextensions import toggle_serverextension_python from notebook import version_info # Command: sudo jupyter nbextension enable --py widgetsnbextension print("Enabling geppettoJupyter extensions ...") isEnabled = enable_nbextension_python('widgetsnbextension') if not isEnabled: raise Exception('Problem enabling widgetsnbextension extension') # Command: sudo jupyter nbextension install --py geppettoJupyter print("Installing geppettoJupyter extension ...") install_nbextension_python('geppettoJupyter', symlink=develop) # Command: sudo jupyter nbextension enable --py geppettoJupyter print("Enabling geppettoJupyter extensions ...") isEnabled = enable_nbextension_python('geppettoJupyter') if not isEnabled: raise Exception('Problem enabling geppettoJupyter extension') # Command: jupyter serverextension enable --py geppettoJupyter print("Enabling server extensions ...") toggle_serverextension_python('geppettoJupyter', enabled=True) # Command: sudo jupyter nbextension install s # Command: sudo jupyter nbextension enable overwrite_get_msg_cell print("Installing and enabling additional geppettoJupyter extension ...") install_nbextension( 'org.geppetto.frontend.jupyter/src/geppettoJupyter/overwrite_get_msg_cell.js', symlink=develop) ext_require_path = 'overwrite_get_msg_cell' if version_info[0] > 4: # notebook 5.x from notebook.nbextensions import enable_nbextension enable_nbextension('notebook', ext_require_path) else: # notebook 4.x from notebook.nbextensions import EnableNBExtensionApp EnableNBExtensionApp().toggle_nbextension(ext_require_path)
def activate_student(self, sys_prefix=True, user=False): print( f"Activate student mode with sys_prefix = {sys_prefix} and user = {user}" ) # Enable server extensions self.enable_serverextension_py("nbgrader", sys_prefix=sys_prefix, user=user) self.disable_serverextension("nbgrader.server_extensions.formgrader") self.disable_serverextension( "nbgrader.server_extensions.assignment_list") self.enable_serverextension_py("e2xgrader", sys_prefix=sys_prefix, user=user) self.disable_serverextension("e2xgrader.server_extensions.formgrader") # Install nbgrader nbextensions self.install_nbextensions("nbgrader", sys_prefix=sys_prefix, user=user) enable_nbextension( require="assignment_list/main", section="tree", sys_prefix=sys_prefix, user=user, ) # Install e2xgrader nbextensions self.install_nbextensions("e2xgrader", sys_prefix=sys_prefix, user=user) enable_nbextension( require="extra_cells/main", section="notebook", sys_prefix=sys_prefix, user=user, ) enable_nbextension( require="assignment_extension/main", section="notebook", sys_prefix=sys_prefix, user=user, )
def enable_nglview_js(user=True): enable_nbextension('nglview', '', user=user)
def enable_nbext(): print("Enabling the nbextension ...") enable_nbextension('notebook', 'cite2c/main', user=True)
def enable_nglview_js(): enable_nbextension('nglview-js', '')
def run(self): from notebook.nbextensions import enable_nbextension _install.run(self) enable_nbextension('notebook', 'gp-mode/main')