From 6371f8aec2e27d9f7349dfebdd71074e76e5f655 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 24 Mar 2016 15:23:32 +0100 Subject: [PATCH] add `--system` flag for enable/disable add more docs coverage, help output So that the three cases are covered: - system-wide (default for install) - user (default for enable) - sys-prefix --- ...upyter Extensions as Python Packages.ipynb | 4 +-- docs/source/extending/frontend_extensions.rst | 14 +++++--- notebook/nbextensions.py | 32 ++++++++++++++----- notebook/serverextensions.py | 22 +++++++++++-- 4 files changed, 55 insertions(+), 17 deletions(-) diff --git a/docs/source/examples/Notebook/Distributing Jupyter Extensions as Python Packages.ipynb b/docs/source/examples/Notebook/Distributing Jupyter Extensions as Python Packages.ipynb index 1ddadef72..91fe4c521 100644 --- a/docs/source/examples/Notebook/Distributing Jupyter Extensions as Python Packages.ipynb +++ b/docs/source/examples/Notebook/Distributing Jupyter Extensions as Python Packages.ipynb @@ -249,9 +249,9 @@ "\n", "The user can install and enable the extensions with the following set of commands:\n", "```\n", - "jupyter serverextension install --py my_fancy_module [--sys-prefix|--user]\n", "jupyter nbextension install --py my_fancy_module [--sys-prefix|--user]\n", - "jupyter nbextension enable --py my_fancy_module [--sys-prefix]\n", + "jupyter nbextension enable --py my_fancy_module [--sys-prefix|--system]\n", + "jupyter serverextension enable --py my_fancy_module [--sys-prefix|--system]\n", "```" ] } diff --git a/docs/source/extending/frontend_extensions.rst b/docs/source/extending/frontend_extensions.rst index e23dfdd53..3b55d7f11 100644 --- a/docs/source/extending/frontend_extensions.rst +++ b/docs/source/extending/frontend_extensions.rst @@ -202,10 +202,12 @@ the prefix. For the action name, the following guidelines should be considered: Installing and enabling extensions ---------------------------------- -You can install your nbextension with the command: +You can install your nbextension with the command:: - jupyter nbextension install path/to/my_extension/ + jupyter nbextension install path/to/my_extension/ [--user|--sys-prefix] +The default installation is system-wide. You can use ``--user`` to do a per-user installation, +or ``--sys-prefix`` to install to Python's prefix (e.g. in a virtual or conda environment). Where my_extension is the directory containing the Javascript files. This will copy it to a Jupyter data directory (the exact location is platform dependent - see :ref:`jupyter_path`). @@ -214,11 +216,15 @@ For development, you can use the ``--symlink`` flag to symlink your extension rather than copying it, so there's no need to reinstall after changes. To use your extension, you'll also need to **enable** it, which tells the -notebook interface to load it. You can do that with another command: +notebook interface to load it. You can do that with another command:: - jupyter nbextension enable my_extension/main + jupyter nbextension enable my_extension/main [--sys-prefix] The argument refers to the Javascript module containing your ``load_ipython_extension`` function, which is ``my_extension/main.js`` in this example. There is a corresponding ``disable`` command to stop using an extension without uninstalling it. + +.. versionchanged:: 4.2 + + Added ``--sys-prefix`` argument diff --git a/notebook/nbextensions.py b/notebook/nbextensions.py index 6de4a7a0b..9f259daf9 100644 --- a/notebook/nbextensions.py +++ b/notebook/nbextensions.py @@ -588,12 +588,18 @@ _base_flags.update({ "user" : ({ "BaseNBExtensionApp" : { "user" : True, - }}, "Install to the user's Jupyter directory" + }}, "Apply the operation only for the given user" + ), + "system" : ({ + "BaseNBExtensionApp" : { + "user" : False, + "sys_prefix": False, + }}, "Apply the operation system-wide" ), "sys-prefix" : ({ "BaseNBExtensionApp" : { "sys_prefix" : True, - }}, "Use sys.prefix as the prefix for installing nbextensions" + }}, "Use sys.prefix as the prefix for installing nbextensions (for environments, packaging)" ), "py" : ({ "BaseNBExtensionApp" : { @@ -655,7 +661,7 @@ class InstallNBExtensionApp(BaseNBExtensionApp): Usage - jupyter nbextension install path/url + jupyter nbextension install path|url [--user|--sys-prefix] This copies a file or a folder into the Jupyter nbextensions directory. If a URL is given, it will be downloaded. @@ -764,7 +770,7 @@ class UninstallNBExtensionApp(BaseNBExtensionApp): if len(self.extra_args)