From ce4e3fc189063d6f7fdb5be44890d05867eb7789 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Mon, 7 Mar 2016 12:39:24 -0500 Subject: [PATCH 1/2] cleaning up references to nbextensions in serverextensions --- notebook/serverextensions.py | 41 +++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/notebook/serverextensions.py b/notebook/serverextensions.py index de5838258..095f59cd1 100644 --- a/notebook/serverextensions.py +++ b/notebook/serverextensions.py @@ -12,7 +12,7 @@ import sys from jupyter_core.paths import jupyter_config_path from ._version import __version__ from .nbextensions import ( - BaseNBExtensionApp, ToggleNBExtensionApp, _get_config_dir, + BaseNBExtensionApp, _get_config_dir, GREEN_ENABLED, RED_DISABLED ) @@ -28,22 +28,29 @@ class ArgumentConflict(ValueError): pass -def toggle_serverextension_python(import_name, enabled=None, parent=None, user=False, sys_prefix=False): +def toggle_serverextension_python(import_name, enabled=None, parent=None, + user=False, sys_prefix=False): """Toggle a server extension. - + + By default, toggles the extension in the system-wide Jupyter configuration + location (e.g. /usr/local/etc/jupyter). + Parameters ---------- - + import_name : str - Python import name of the extension + Importable Python module (dotted-notation) exposing the magic-named + `load_jupyter_server_extension` function enabled : bool [default: None] Toggle state for the extension. Set to None to toggle, True to enable, and False to disable the extension. parent : Configurable [default: None] user : bool [default: False] - Whether to install to the user's nbextensions directory. - Otherwise do a system-wide install (e.g. /usr/local/share/jupyter/nbextensions). - sys_prefix : bool [default: False]""" + Toggle in the user's configuration location (e.g. ~/.jupyter). + sys_prefix : bool [default: False] + Toggle in the current Python environment's configuration location + (e.g. ~/.envs/my-env/etc/jupyter). + """ config_dir = _get_config_dir(user=user, sys_prefix=sys_prefix) cm = BaseJSONConfigManager(parent=parent, config_dir=config_dir) cfg = cm.get("jupyter_notebook_config") @@ -78,7 +85,7 @@ flags = { "sys-prefix" : ({ "ToggleServerExtensionApp" : { "sys_prefix" : True, - }}, "Use sys.prefix as the prefix for installing nbextensions" + }}, "Use sys.prefix as the prefix for installing server extensions" ), "py" : ({ "ToggleServerExtensionApp" : { @@ -88,7 +95,8 @@ flags = { } flags['python'] = flags['py'] -class ToggleServerExtensionApp(ToggleNBExtensionApp): + +class ToggleServerExtensionApp(BaseNBExtensionApp): name = "jupyter serverextension enable/disable" description = "Enable/disable a server extension using frontend configuration files." @@ -100,7 +108,7 @@ class ToggleServerExtensionApp(ToggleNBExtensionApp): sys_prefix = Bool(False, config=True, help="Use the sys.prefix as the prefix") python = Bool(False, config=True, help="Install from a Python package") - def toggle_server_extension(self, import_name): + def _toggle_server_extension(self, import_name): toggle_serverextension_python(import_name, self._toggle_value, parent=self, user=self.user, sys_prefix=self.sys_prefix) def toggle_server_extension_python(self, package): @@ -158,9 +166,9 @@ class ListServerExtensionsApp(BaseNBExtensionApp): _examples = """ -jupyter serverextension list # list all configured nbextensions -jupyter serverextension enable --py # enable all nbextensions in a Python package -jupyter serverextension disable --py # disable all nbextensions in a Python package +jupyter serverextension list # list all configured server extensions +jupyter serverextension enable --py # enable all server extensions in a Python package +jupyter serverextension disable --py # disable all server extensions in a Python package """ @@ -195,9 +203,8 @@ main = ServerExtensionApp.launch_instance def _get_server_extension_metadata(package): m = __import__(package) if not hasattr(m, '_jupyter_server_extension_paths'): - raise KeyError('The Python package {} is not a valid server extension'.format(package)) - nbexts = m._jupyter_server_extension_paths() - return m, nbexts + raise KeyError('The Python package {} does not include any valid server extensions'.format(package)) + return m, m._jupyter_server_extension_paths() if __name__ == '__main__': main() From 2b43653ac355036887e74f69193f7c4fa0f86ccb Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Mon, 7 Mar 2016 12:44:00 -0500 Subject: [PATCH 2/2] actually, should be public --- notebook/serverextensions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notebook/serverextensions.py b/notebook/serverextensions.py index 095f59cd1..dce0003ea 100644 --- a/notebook/serverextensions.py +++ b/notebook/serverextensions.py @@ -108,14 +108,14 @@ class ToggleServerExtensionApp(BaseNBExtensionApp): sys_prefix = Bool(False, config=True, help="Use the sys.prefix as the prefix") python = Bool(False, config=True, help="Install from a Python package") - def _toggle_server_extension(self, import_name): + def toggle_server_extension(self, import_name): toggle_serverextension_python(import_name, self._toggle_value, parent=self, user=self.user, sys_prefix=self.sys_prefix) def toggle_server_extension_python(self, package): m, server_exts = _get_server_extension_metadata(package) for server_ext in server_exts: require = server_ext['require'] - self._toggle_server_extension(require) + self.toggle_server_extension(require) def start(self):