Skip to content

Commit 9ef90bb

Browse files
authored
Merge pull request #321 from Zsailer/classic_server_extension
Enable ExtensionApps to work with classic notebook server
2 parents f1add85 + ce6c87f commit 9ef90bb

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

docs/source/developers/extensions.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ To make your extension executable from anywhere on your system, point an entry-p
299299
}
300300
)
301301
302+
``ExtensionApp`` as a classic Notebook server extension
303+
-------------------------------------------------------
304+
305+
An extension that extends ``ExtensionApp`` should still work with the old Tornado server from the classic Jupyter Notebook. The ``ExtensionApp`` class
306+
provides a method, ``load_classic_server_extension``, that handles the extension initialization. Simply define a ``load_jupyter_server_extension`` reference
307+
pointing at the ``load_classic_server_extension`` method:
308+
309+
.. code-block:: python
310+
311+
# This is typically defined in the root `__init__.py`
312+
# file of the extension package.
313+
load_jupyter_server_extension = MyExtensionApp.load_classic_server_extension
314+
315+
316+
If the extension is enabled, the extension will be loaded when the server starts.
317+
318+
302319
Distributing a server extension
303320
===============================
304321

jupyter_server/extension/application.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from traitlets.config import Config
1515
from tornado.log import LogFormatter
16+
from tornado.web import RedirectHandler
1617

1718
from jupyter_core.application import JupyterApp
1819

@@ -21,7 +22,6 @@
2122
from jupyter_server.utils import url_path_join
2223
from .handler import ExtensionHandlerMixin
2324

24-
2525
# -----------------------------------------------------------------------------
2626
# Util functions and classes.
2727
# -----------------------------------------------------------------------------
@@ -422,6 +422,36 @@ def _load_jupyter_server_extension(cls, serverapp):
422422
extension.initialize()
423423
return extension
424424

425+
@classmethod
426+
def load_classic_server_extension(cls, serverapp):
427+
"""Enables extension to be loaded as classic Notebook (jupyter/notebook) extension.
428+
"""
429+
extension = cls()
430+
extension.serverapp = serverapp
431+
extension.load_config_file()
432+
extension.update_config(serverapp.config)
433+
extension.parse_command_line(serverapp.extra_args)
434+
# Add redirects to get favicons from old locations in the classic notebook server
435+
extension.handlers.extend([
436+
(r"/static/favicons/favicon.ico", RedirectHandler,
437+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon.ico")}),
438+
(r"/static/favicons/favicon-busy-1.ico", RedirectHandler,
439+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-busy-1.ico")}),
440+
(r"/static/favicons/favicon-busy-2.ico", RedirectHandler,
441+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-busy-2.ico")}),
442+
(r"/static/favicons/favicon-busy-3.ico", RedirectHandler,
443+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-busy-3.ico")}),
444+
(r"/static/favicons/favicon-file.ico", RedirectHandler,
445+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-file.ico")}),
446+
(r"/static/favicons/favicon-notebook.ico", RedirectHandler,
447+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-notebook.ico")}),
448+
(r"/static/favicons/favicon-terminal.ico", RedirectHandler,
449+
{"url": url_path_join(serverapp.base_url, "static/base/images/favicon-terminal.ico")}),
450+
(r"/static/logo/logo.png", RedirectHandler,
451+
{"url": url_path_join(serverapp.base_url, "static/base/images/logo.png")}),
452+
])
453+
extension.initialize()
454+
425455
@classmethod
426456
def launch_instance(cls, argv=None, **kwargs):
427457
"""Launch the extension like an application. Initializes+configs a stock server

0 commit comments

Comments
 (0)