Skip to content

Commit

Permalink
Merge pull request #214 from Zsailer/other-extensions
Browse files Browse the repository at this point in the history
Add option to load extensions listed on jupyter_config_path
  • Loading branch information
Zsailer authored Apr 29, 2020
2 parents 2f02e93 + 643765d commit 4f2d91d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
}
})
serverapp = ServerApp.instance(**kwargs, argv=[], config=config)
serverapp.initialize(argv=argv, load_extensions=load_other_extensions)
serverapp.initialize(argv=argv, find_extensions=load_other_extensions)
return serverapp

def link_to_serverapp(self, serverapp):
Expand Down
38 changes: 20 additions & 18 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,18 +1482,12 @@ def init_components(self):
# TODO: this should still check, but now we use bower, not git submodule
pass

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

# Step 2: Load extension metadata for enabled extensions, load config for
def init_server_extensions(self):
"""
If an extension's metadata includes an 'app' key,
the value must be a subclass of ExtensionApp. An instance
of the class will be created at this step. The config for
this instance will inherit the ServerApp's config object
and load its own config.
"""
# Load extension metadata for enabled extensions, load config for
# enabled ExtensionApps, and store enabled extension metadata in the
# _enabled_extensions attribute.
#
Expand Down Expand Up @@ -1758,17 +1760,18 @@ def _init_asyncio_patch():
asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())

@catch_config_error
def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
def initialize(self, argv=None, find_extensions=True, new_httpserver=True):
"""Initialize the Server application class, configurables, web application, and http server.
Parameters
----------
argv: list or None
CLI arguments to parse.
load_extensions: bool
If True, the server will load server extensions listed in the jpserver_extension trait.
Otherwise, no server extensions will be loaded.
find_extensions: bool
If True, find and load extensions listed in Jupyter config paths. If False,
only load extensions that are passed to ServerApp directy through
the `argv`, `config`, or `jpserver_extensions` arguments.
new_httpserver: bool
If True, a tornado HTTPServer instance will be created and configured for the Server Web
Expand All @@ -1778,11 +1781,11 @@ def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
# Parse command line, load ServerApp config files,
# and update ServerApp config.
super(ServerApp, self).initialize(argv)

# Then, use extensions' config loading mechanism to
# update config. ServerApp config takes precedence.
if load_extensions:
self.init_server_extensions()
if find_extensions:
self.find_server_extensions()
self.init_server_extensions()
# Initialize all components of the ServerApp.
self.init_logging()
if self._dispatching:
Expand All @@ -1794,8 +1797,7 @@ def initialize(self, argv=None, load_extensions=True, new_httpserver=True):
self.init_httpserver()
self.init_terminals()
self.init_signal()
if load_extensions:
self.load_server_extensions()
self.load_server_extensions()
self.init_mime_overrides()
self.init_shutdown_no_activity()

Expand Down

0 comments on commit 4f2d91d

Please sign in to comment.