Merge pull request #14 from willingc/update-nb

Update nbextensions notebook from @nbollweg
pull/879/head
Jonathan Frederic 10 years ago
commit 4db4691563

@ -11,31 +11,42 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## How can the notebook be extended?\n",
"The Jupyter Notebook server and client application are both deeply customizable. Their behavior can be extended by, respectively:\n",
"## Overview\n",
"### How can the notebook be extended?\n",
"The Jupyter Notebook client and server application are both deeply customizable. Their behavior can be extended by creating, respectively:\n",
"\n",
"- nbextension:\n",
" - a single JS file, or directory of JavaScript, Cascading StyleSheets, etc. that contain at least\n",
" - a JavaScript module packaged as an [AMD modules](https://en.wikipedia.org/wiki/Asynchronous_module_definition)\n",
" - that exports a function `load_ipython_extension`\n",
"- nbextension: a notebook extension\n",
" - a single JS file, or directory of JavaScript, Cascading StyleSheets, etc. that contain at\n",
" minimum a JavaScript module packaged as an\n",
" [AMD modules(https://en.wikipedia.org/wiki/Asynchronous_module_definition)\n",
" that exports a function `load_ipython_extension`\n",
"- server extension: an importable Python module\n",
" - that implements `load_jupyter_server_extension`\n",
"\n",
"Since it is somewhat rare to have a server extension that does not have any frontend components, for convenience ad consistency, all these assets can be versioned together, with a few simple commands to make installing them easy and less error-prone for the user. "
" - that implements `load_jupyter_server_extension`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Why create a Python package for Jupyter extensions?\n",
"Since it is rare to have a server extension that does not have any frontend components (an nbextension), for convenience and consistency, all these client and server extensions with their assets can be packaged and versioned together as a Python package with a few simple commands. This makes installing the package of extensions easier and less error-prone for the user. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install a Python Package with Jupyter Extensions\n",
"There are many ways someone may get the enclosing python package:\n",
"## Installation of Jupyter Extensions\n",
"### Install a Python package containing Jupyter Extensions\n",
"There are several ways that you may get a Python package containing Jupyter Extensions. Commonly, you will use a package manager for your system:\n",
"```shell\n",
"pip install some_package\n",
"pip install helpful_package\n",
"# or\n",
"conda install some_package\n",
"conda install helpful_package\n",
"# or\n",
"apt-get install some_package\n",
"apt-get install helpful_package\n",
"\n",
"# where 'helpful_package' is a Python package containing one or more Jupyter Extensions\n",
"```"
]
},
@ -43,17 +54,21 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enable a Server Extension\n",
"### Enable a Server Extension\n",
"\n",
"The simplest case would be to enable a server extension which has no frontend components. \n",
"\n",
"For the simplest case, a server extension with no frontend components, a `pip` user that wants their configuration stored in their home directory would type:\n",
"A `pip` user that wants their configuration stored in their home directory would type the following command:\n",
"```shell\n",
"jupyter serverextension enable --py some_package --user\n",
"jupyter serverextension enable --py helpful_package --user\n",
"```\n",
"\n",
"A `virtualenv` or `conda` user can pass `--sys-prefix` insted of `--user` to keep their environment reproducible.\n",
"Alternatively, a `virtualenv` or `conda` user can pass `--sys-prefix` instead of `--user` which keeps their environment isolated and reproducible. For example:\n",
"```shell\n",
"# Make sure that your virtualenv or conda environment is activated\n",
"[source] activate my-environment\n",
"jupyter serverextension enable --py some_package --sys-prefix\n",
"\n",
"jupyter serverextension enable --py helpful_package --sys-prefix\n",
"```"
]
},
@ -61,16 +76,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install the nbextension assets"
"### Install the nbextension assets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In any event, if a package also has frontend assets that must be available (but not neccessarily enabled by default):\n",
"If a package also has an nbextension with frontend assets that must be available (but not neccessarily enabled by default), install these assets with the following command:\n",
"```shell\n",
"jupyter nbextension install --py some_package --user # or --sys-prefix\n",
"jupyter nbextension install --py helpful_package --user # or --sys-prefix if using virtualenv or conda\n",
"```"
]
},
@ -78,16 +93,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enable nbextension assets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, if a package has extensions that need to be required in the browser without user interactions,\n",
"### Enable nbextension assets\n",
"If a package has assets that should be loaded every time a Jupyter app (e.g. lab, notebook, dashboard, terminal) is loaded in the browser, the following command can be used to enable the nbextension:\n",
"```shell\n",
"jupyter nbextension enable --py some_package --user # or --sys-prefix\n",
"jupyter nbextension enable --py helpful_package --user # or --sys-prefix if using virtualenv or conda\n",
"```"
]
},
@ -95,8 +104,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Did it work?\n",
"After running some extension install steps, one can list what is presently known about, whether it's enabled, etc.\n",
"## Did it work? Check by listing Jupyter Extensions.\n",
"After running one or more extension installation steps, you can list what is presently known about nbextensions or server extension. The following commands will list which extensions are available, whether they are enabled, and other extension details:\n",
"\n",
"```shell\n",
"jupyter nbextension list\n",
@ -108,6 +117,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Additional resources on creating and distributing packages \n",
"\n",
"> Of course, in addition to the files listed, there are number of other files one needs to build a proper package. Here are some good resources:\n",
"- [The Hitchhiker's Guide to Packaging](http://the-hitchhikers-guide-to-packaging.readthedocs.org/en/latest/quickstart.html)\n",
"- [Repository Structure and Python](http://www.kennethreitz.org/essays/repository-structure-and-python) by Kenneth Reitz\n",
@ -124,14 +135,16 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Implementing Python-wrapped extensions"
"## Example - Server extension"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is an example of a python module which contains a server extension directly on itself. It has this directory structure\n",
"### Creating a Python package with a server extension\n",
"\n",
"Here is an example of a python module which contains a server extension directly on itself. It has this directory structure:\n",
"```\n",
"- setup.py\n",
"- MANIFEST.in\n",
@ -144,7 +157,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### `my_module/__init__.py`\n",
"### Defining the server extension\n",
"This example shows that the server extension and its `load_jupyter_server_extension` function are defined in the `__init__.py` file.\n",
"#### `my_module/__init__.py`\n",
"\n",
"```python\n",
"def _jupyter_server_extension_paths():\n",
@ -162,6 +177,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### Install and enable the server extension\n",
"Which a user can install with:\n",
"```\n",
"jupyter serverextension enable --py my_module [--sys-prefix|--user]\n",
@ -172,6 +188,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example - Server extension and nbextension"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating a Python package with a server extension and nbextension\n",
"Here is another server extension, with a front-end module. It assumes this directory structure:\n",
"\n",
"```\n",
@ -190,7 +214,10 @@
"collapsed": true
},
"source": [
"### `my_fancy_module/__init__.py`\n",
"### Defining the server extension and nbextension\n",
"This example again shows that the server extension and its `load_jupyter_server_extension` function are defined in the `__init__.py` file. This time, there is also a function `_jupyter_nbextension_path` for the nbextension.\n",
"\n",
"#### `my_fancy_module/__init__.py`\n",
"\n",
"```python\n",
"def _jupyter_server_extension_paths():\n",
@ -218,7 +245,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Which a user can install with:\n",
"### Install and enable the server extension and nbextension\n",
"\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",

Loading…
Cancel
Save