Skip to content

Commit 9d4354d

Browse files
committed
server extension migration documentation
1 parent 523f198 commit 9d4354d

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

docs/source/developers/extensions.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,81 @@ Putting it all together, authors can distribute their extension following this s
401401
.. links
402402
403403
.. _`Jupyter's paths`: https://jupyter.readthedocs.io/en/latest/projects/jupyter-directories.html
404+
405+
406+
Migrating an extension to use Jupyter Server
407+
============================================
408+
409+
If you're a developer of a `classic Notebook Server`_ extension, your extension should be able to work with *both* the classic notebook server and ``jupyter_server``.
410+
411+
There are two key steps to make this happen:
412+
413+
1. Point Jupyter Server to the ``load_jupyter_server_extension`` function with a new reference name.
414+
The ``load_jupyter_server_extension`` function was the key to loading a server extension in the classic Notebook Server. Jupyter Server expects the name of this function to be prefixed with an underscore—i.e. ``_load_jupyter_server_extension``. You can easily achieve this by adding a reference to the old function name with the new name in the same module.
415+
416+
.. code-block:: python
417+
418+
def load_jupyter_server_extension(nbapp):
419+
...
420+
421+
# Reference the old function name with the new function name.
422+
423+
_load_jupyter_server_extension = load_jupyter_server_extension
424+
425+
2. Add new data files to your extension package that enable it with Jupyter Server.
426+
This new file can go next to your classic notebook server data files. Create a new sub-directory, ``jupyter_server_config.d``, and add a new ``.json`` file there:
427+
428+
.. raw:: html
429+
430+
<pre>
431+
myextension
432+
├── myextension/
433+
│ ├── __init__.py
434+
│ └── app.py
435+
├── jupyter-config/
436+
│ └── jupyter_notebook_config.d/
437+
│ └── myextension.json
438+
│ <b>└── jupyter_server_config.d/</b>
439+
│ <b>└── myextension.json</b>
440+
└── setup.py
441+
</pre>
442+
443+
The new ``.json`` file should look something like this (you'll notice the changes in the configured class and trait names):
444+
445+
.. code-block:: json
446+
447+
{
448+
"ServerApp": {
449+
"jpserver_extensions": {
450+
"myextension": true
451+
}
452+
}
453+
}
454+
455+
Update your extension package's ``setup.py`` so that the data-files are moved into the jupyter configuration directories when users download the package.
456+
457+
.. code-block:: python
458+
459+
from setuptools import setup
460+
461+
setup(
462+
name="myextension",
463+
...
464+
include_package_data=True,
465+
data_files=[
466+
(
467+
"etc/jupyter/jupyter_server_config.d",
468+
["jupyter-config/jupyter_server_config.d/myextension.json"]
469+
),
470+
(
471+
"etc/jupyter/jupyter_notebook_config.d",
472+
["jupyter-config/jupyter_notebook_config.d/myextension.json"]
473+
),
474+
]
475+
476+
)
477+
478+
479+
480+
481+
.. _`classic Notebook Server`: https://jupyter-notebook.readthedocs.io/en/stable/extending/handlers.html

0 commit comments

Comments
 (0)