def enable_extentions(): print("Trying to enable extensions") # this is for normal users # for developers, you should know what to do. :D try: # enable_nbextension_python does not exist in older notebook # use try ... except in case users do not have notebook yet from notebook.nbextensions import enable_nbextension_python from nglview.install import install_nglview_js_widgets from nglview.install import enable_nglview_js_widgets enable_nbextension_python('widgetsnbextension') # user=True # TODO: sys_prefix? Using user specified option? (--user) install_nglview_js_widgets(user=True, debug=True) enable_nglview_js_widgets(user=True) print("Seems OK") except (ImportError, OSError) as e: # TODO: add type of exception here? # Case: # - notebook is not installed before nglview # - permission denied? print('Failed to enable extensions.') print(e) print('Skip')
def test_nbextension_validate(self): # Break the metadata (correct file will still be copied) self._inject_mock_extension('notebook') install_nbextension_python('mockextension', user=True) enable_nbextension_python('mockextension') warnings = validate_nbextension("_mockdestination/index") self.assertEqual([], warnings, warnings)
def test_nbextensionpy_validate(self): self._inject_mock_extension('notebook') paths = install_nbextension_python('mockextension', user=True) enable_nbextension_python('mockextension') meta = self._mock_extension_spec_meta() warnings = validate_nbextension_python(meta, paths[0]) self.assertEqual([], warnings, warnings)
def test_nbextensionpy_enable(self): self._inject_mock_extension('notebook') install_nbextension_python('mockextension', user=True) enable_nbextension_python('mockextension') 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('_mockdestination/index', False) assert enabled
def test_nbextensionpy_validate_bad(self): # Break the metadata (correct file will still be copied) self._inject_mock_extension('notebook') paths = install_nbextension_python('mockextension', user=True) enable_nbextension_python('mockextension') meta = self._mock_extension_spec_meta() meta.update(require="bad-require") warnings = validate_nbextension_python(meta, paths[0]) self.assertNotEqual([], warnings, warnings)
def install_nbextension(): print("Trying to install pyforest nbextension...") try: from notebook import nbextensions except ImportError: print( "Could not install pyforest Jupyter Notebook extension because Jupyter Notebook is not available" ) return nbextensions.install_nbextension_python("pyforest") nbextensions.enable_nbextension_python("pyforest") print("") print("Finished installing the pyforest Jupyter Notebook nbextension") print("Please reload your Jupyter notebook browser window")
def add_xunit(self): """ Hack the setup in the middle (after paths, before server) """ super(NBAnacondaCloudTestController, self).add_xunit() with patch.dict(os.environ, self.env.copy()): sys_prefix = True pkg = "nb_anacondacloud" nbextensions.install_nbextension_python( pkg, sys_prefix=sys_prefix) nbextensions.enable_nbextension_python( pkg, sys_prefix=sys_prefix) serverextensions.toggle_serverextension_python( pkg, sys_prefix=sys_prefix) if (self.section == "auth") and self.use_token(): home = os.environ["HOME"] _data_dir = "".join([ self.home.name, dirs.user_data_dir[len(home):]]) with open(TEST_LOG, "a+") as fp: fp.write("\nCopying auth token to {}\n".format( _data_dir )) shutil.copytree( dirs.user_data_dir, _data_dir ) patch_auth = (self.section == "auth") and not self.use_token() serverextensions.toggle_serverextension_python( import_name="nb_anacondacloud.tests.patched", enabled=patch_auth, sys_prefix=sys_prefix) serverextensions.toggle_serverextension_python( import_name=pkg, enabled=not patch_auth, sys_prefix=sys_prefix)
def run(self): install.run(self) log.info( 'Attempting to install and enable transmart-aborist extension.') log.info('This can be done manually by running.') log.info(' $ jupyter nbextension install --py tmtk.arborist') log.info(' $ jupyter serverextension enable --py tmtk.arborist') try: import notebook except ImportError: log.info( "Cannot find module 'notebook'. Aborting automated install.") return notebook_version = getattr(notebook, '__version__') if notebook_version is None or notebook_version < '4.2.0': log.info( "Version of notebook package should be at least 4.2.0 for Arborist, consider:" ) log.info(" $ pip3 install --upgrade notebook") log.info('Aborting automated install.') return from notebook.nbextensions import install_nbextension_python, enable_nbextension_python from notebook.serverextensions import toggle_serverextension_python, validate_serverextension enable_nbextension_python('widgetsnbextension', sys_prefix=True) install_nbextension_python('tmtk.arborist', sys_prefix=True, overwrite=True) toggle_serverextension_python('tmtk.arborist', enabled=True, sys_prefix=True) warnings = validate_serverextension('tmtk.arborist') if warnings: [log.warn(warning) for warning in warnings] else: log.info('Extension has been 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)
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)
'Topic :: Utilities', ], ) if 'install' in argv: import sys x = sys.stdout.write(msg) import site try: import importlib importlib.reload(site) except: reload(site) import latex_envs import notebook.nbextensions as nb user = False sys_prefix = False if "--user" in argv: user = True if "--sys-prefix" in argv: sys_prefix = True x = sys.stdout.write("[Step 2]: Installing the javascript nbextension" + "\n") nb.install_nbextension_python('latex_envs', user=user, sys_prefix=sys_prefix) x = sys.stdout.write("[Step 3]: Enabing the nbextension" + "\n") nb.enable_nbextension_python('latex_envs', user=user, sys_prefix=sys_prefix)
def enable_nglview_js_widgets(user=True): nbextensions.enable_nbextension_python('nglview', user=user)
from notebook.notebookapp import main from notebook.nbextensions import install_nbextension_python, enable_nbextension_python from notebook.serverextensions import toggle_serverextension_python import sys import subprocess if __name__ == "__main__": # enable the jupytext server extension toggle_serverextension_python("jupytext", enabled=True) # install and enable the jupytext notebook extension install_nbextension_python("jupytext", user=True) enable_nbextension_python("jupytext") # we have to manually enable the "widgetsnbextension" notebook extension to use ipywidgets inside our hermetic # python interpreter install_nbextension_python("widgetsnbextension", user=True) enable_nbextension_python("widgetsnbextension") sys.exit(main(argv=["--no-browser"]))
def install_nbextension(): install_nbextension_python('iclientpy', overwrite=True, symlink=True, sys_prefix=True) enable_nbextension_python('iclientpy', sys_prefix=True)