Skip to content

Commit c1b7618

Browse files
authored
Merge pull request #3520 from bollwyvl/docs/confd-example
update docs with confd implementation details
2 parents 85b60e2 + fed254b commit c1b7618

File tree

1 file changed

+136
-2
lines changed

1 file changed

+136
-2
lines changed

docs/source/examples/Notebook/Distributing Jupyter Extensions as Python Packages.ipynb

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"metadata": {},
3232
"source": [
3333
"### Why create a Python package for Jupyter extensions?\n",
34-
"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. "
34+
"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, or as of Notebook 5.3, handled automatically by your package manager of choice. This makes installing the package of extensions easier and less error-prone for the user."
3535
]
3636
},
3737
{
@@ -52,6 +52,16 @@
5252
"```"
5353
]
5454
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"### Automatic installation and Enabling\n",
60+
"> New in Notebook 5.3\n",
61+
"\n",
62+
"The absolute simplest case requires no user interaction at all! Configured correctly, after installing with their package manager of choice, both server and frontend extensions can be enabled by default in the environment where they were installed, i.e. `--sys-prefix`. See the `setup.py` in the example below."
63+
]
64+
},
5565
{
5666
"cell_type": "markdown",
5767
"metadata": {},
@@ -259,6 +269,130 @@
259269
"```"
260270
]
261271
},
272+
{
273+
"cell_type": "markdown",
274+
"metadata": {},
275+
"source": [
276+
"### Automatically enabling a server extension and nbextension\n",
277+
"> New in Notebook 5.3\n",
278+
"\n",
279+
"Server extensions and nbextensions can be installed and enabled without any user intervention or post-install scripts beyond `<package manager> install <extension package name>`"
280+
]
281+
},
282+
{
283+
"cell_type": "markdown",
284+
"metadata": {},
285+
"source": [
286+
"In addition to the `my_fancy_module` file tree, assume:\n",
287+
"- `jupyter-config/`\n",
288+
" - `jupyter_notebook_config.d/`\n",
289+
" - `my_fancy_module.json`\n",
290+
" - `nbconfig/`\n",
291+
" - `notebook.d/`\n",
292+
" - `my_fancy_module.json`"
293+
]
294+
},
295+
{
296+
"cell_type": "markdown",
297+
"metadata": {},
298+
"source": [
299+
"#### `jupyter-config/jupyter_notebook_config.d/my_fancy_module.json`\n",
300+
"```json\n",
301+
"{\n",
302+
" \"NotebookApp\": {\n",
303+
" \"nbserver_extensions\": {\n",
304+
" \"my_fancy_module\": true\n",
305+
" }\n",
306+
" }\n",
307+
"}\n",
308+
"```"
309+
]
310+
},
311+
{
312+
"cell_type": "markdown",
313+
"metadata": {},
314+
"source": [
315+
"#### `jupyter-config/nbconfig/notebook.d/my_fancy_module.json`\n",
316+
"```json\n",
317+
"{\n",
318+
" \"load_extensions\": {\n",
319+
" \"my_fancy_module/index\": true\n",
320+
" }\n",
321+
"}\n",
322+
"```"
323+
]
324+
},
325+
{
326+
"cell_type": "markdown",
327+
"metadata": {},
328+
"source": [
329+
"Put all of them in place via:\n",
330+
"\n",
331+
"#### `setup.py`\n",
332+
"```python\n",
333+
"import setuptools\n",
334+
"\n",
335+
"setuptools.setup(\n",
336+
" name=\"MyFancyModule\",\n",
337+
" ...\n",
338+
" include_package_data=True,\n",
339+
" data_files=[\n",
340+
" # like `jupyter nbextension install --sys-prefix`\n",
341+
" (\"share/jupyter/nbextensions/my_fancy_module\", [\n",
342+
" \"my_fancy_module/static/index.js\",\n",
343+
" ]),\n",
344+
" # like `jupyter nbextension enable --sys-prefix`\n",
345+
" (\"etc/jupyter/nbconfig/notebook.d\", [\n",
346+
" \"jupyter-config/nbconfig/notebook.d/my_fancy_module.json\"\n",
347+
" ]),\n",
348+
" # like `jupyter serverextension enable --sys-prefix`\n",
349+
" (\"etc/jupyter/jupyter_notebook_config.d\", [\n",
350+
" \"jupyter-config/jupyter_notebook_config.d/my_fancy_module.json\"\n",
351+
" ])\n",
352+
" ],\n",
353+
" ...\n",
354+
" zip_safe=False\n",
355+
")\n",
356+
"```"
357+
]
358+
},
359+
{
360+
"cell_type": "markdown",
361+
"metadata": {},
362+
"source": [
363+
"and last, but not least:\n",
364+
"\n",
365+
"#### `MANIFEST.in`\n",
366+
"```config\n",
367+
"recursive-include jupyter-config *.json\n",
368+
"recursive-include my_fancy_module/static *.js\n",
369+
"```"
370+
]
371+
},
372+
{
373+
"cell_type": "markdown",
374+
"metadata": {},
375+
"source": [
376+
"As most package managers will only modify their environment, the eventual configuration will be as if the user had typed:\n",
377+
"```\n",
378+
"jupyter nbextension install --py my_fancy_module --sys-prefix\n",
379+
"jupyter nbextension enable --py my_fancy_module --sys-prefix\n",
380+
"jupyter serverextension enable --py my_fancy_module --sys-prefix\n",
381+
"```\n",
382+
"\n",
383+
"If a user manually `disable`s an extension, that configuration will override the bundled package configuration."
384+
]
385+
},
386+
{
387+
"cell_type": "markdown",
388+
"metadata": {},
389+
"source": [
390+
"#### When automagical install fails\n",
391+
"Note this can still fail in certain situations with `pip`, requiring manual use of `install` and `enable` commands.\n",
392+
"\n",
393+
"Non-python-specific package managers (e.g. `conda`, `apt`) may choose not to implement the above behavior at the `setup.py` level, having more ways to put data files in various places at build time."
394+
]
395+
},
262396
{
263397
"cell_type": "markdown",
264398
"metadata": {},
@@ -368,7 +502,7 @@
368502
"name": "python",
369503
"nbconvert_exporter": "python",
370504
"pygments_lexer": "ipython3",
371-
"version": "3.5.1"
505+
"version": "3.6.5"
372506
}
373507
},
374508
"nbformat": 4,

0 commit comments

Comments
 (0)