Skip to content

Commit 4f2d91d

Browse files
authored
Merge pull request #214 from Zsailer/other-extensions
Add option to load extensions listed on jupyter_config_path
2 parents 2f02e93 + 643765d commit 4f2d91d

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

jupyter_server/extension/application.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
316316
}
317317
})
318318
serverapp = ServerApp.instance(**kwargs, argv=[], config=config)
319-
serverapp.initialize(argv=argv, load_extensions=load_other_extensions)
319+
serverapp.initialize(argv=argv, find_extensions=load_other_extensions)
320320
return serverapp
321321

322322
def link_to_serverapp(self, serverapp):

jupyter_server/serverapp.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,18 +1482,12 @@ def init_components(self):
14821482
# TODO: this should still check, but now we use bower, not git submodule
14831483
pass
14841484

1485-
def init_server_extensions(self):
1485+
def find_server_extensions(self):
14861486
"""
14871487
Searches Jupyter paths for jpserver_extensions and captures
14881488
metadata for all enabled extensions.
1489-
1490-
If an extension's metadata includes an 'app' key,
1491-
the value must be a subclass of ExtensionApp. An instance
1492-
of the class will be created at this step. The config for
1493-
this instance will inherit the ServerApp's config object
1494-
and load its own config.
14951489
"""
1496-
# Step 1: Walk through all config files looking for jpserver_extensions.
1490+
# Walk through all config files looking for jpserver_extensions.
14971491
#
14981492
# Each extension will likely have a JSON config file enabling itself in
14991493
# the "jupyter_server_config.d" directory. Find each of these and
@@ -1521,7 +1515,15 @@ def init_server_extensions(self):
15211515
self.config.ServerApp.jpserver_extensions.update({modulename: enabled})
15221516
self.jpserver_extensions.update({modulename: enabled})
15231517

1524-
# Step 2: Load extension metadata for enabled extensions, load config for
1518+
def init_server_extensions(self):
1519+
"""
1520+
If an extension's metadata includes an 'app' key,
1521+
the value must be a subclass of ExtensionApp. An instance
1522+
of the class will be created at this step. The config for
1523+
this instance will inherit the ServerApp's config object
1524+
and load its own config.
1525+
"""
1526+
# Load extension metadata for enabled extensions, load config for
15251527
# enabled ExtensionApps, and store enabled extension metadata in the
15261528
# _enabled_extensions attribute.
15271529
#
@@ -1758,17 +1760,18 @@ def _init_asyncio_patch():
17581760
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())
17591761

17601762
@catch_config_error
1761-
def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
1763+
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
17621764
"""Initialize the Server application class, configurables, web application, and http server.
17631765
17641766
Parameters
17651767
----------
17661768
argv: list or None
17671769
CLI arguments to parse.
17681770
1769-
load_extensions: bool
1770-
If True, the server will load server extensions listed in the jpserver_extension trait.
1771-
Otherwise, no server extensions will be loaded.
1771+
find_extensions: bool
1772+
If True, find and load extensions listed in Jupyter config paths. If False,
1773+
only load extensions that are passed to ServerApp directy through
1774+
the `argv`, `config`, or `jpserver_extensions` arguments.
17721775
17731776
new_httpserver: bool
17741777
If True, a tornado HTTPServer instance will be created and configured for the Server Web
@@ -1778,11 +1781,11 @@ def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
17781781
# Parse command line, load ServerApp config files,
17791782
# and update ServerApp config.
17801783
super(ServerApp, self).initialize(argv)
1781-
17821784
# Then, use extensions' config loading mechanism to
17831785
# update config. ServerApp config takes precedence.
1784-
if load_extensions:
1785-
self.init_server_extensions()
1786+
if find_extensions:
1787+
self.find_server_extensions()
1788+
self.init_server_extensions()
17861789
# Initialize all components of the ServerApp.
17871790
self.init_logging()
17881791
if self._dispatching:
@@ -1794,8 +1797,7 @@ def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
17941797
self.init_httpserver()
17951798
self.init_terminals()
17961799
self.init_signal()
1797-
if load_extensions:
1798-
self.load_server_extensions()
1800+
self.load_server_extensions()
17991801
self.init_mime_overrides()
18001802
self.init_shutdown_no_activity()
18011803

0 commit comments

Comments
 (0)