Skip to content

Commit

Permalink
Fix loading of sibling extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
afshin committed Apr 21, 2021
1 parent 8bfdd40 commit 0d11ffc
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
12 changes: 8 additions & 4 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,13 +477,18 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
The `launch_instance` method uses this method to initialize
and start a server.
"""
jpserver_extensions = {cls.get_extension_package(): True}
find_extensions = cls.load_other_extensions
if 'jpserver_extensions' in cls.serverapp_config:
jpserver_extensions.update(cls.serverapp_config['jpserver_extensions'])
cls.serverapp_config['jpserver_extensions'] = jpserver_extensions
find_extensions = False
serverapp = ServerApp.instance(
jpserver_extensions={cls.get_extension_package(): True}, **kwargs)
serverapp.aliases.update(cls.aliases)
jpserver_extensions=jpserver_extensions, **kwargs)
serverapp.initialize(
argv=argv,
starter_extension=cls.name,
find_extensions=cls.load_other_extensions,
find_extensions=find_extensions,
)
return serverapp

Expand All @@ -510,7 +515,6 @@ def launch_instance(cls, argv=None, **kwargs):
# before initializing server to make sure these
# arguments trigger actions from the extension not the server.
_preparse_for_stopping_flags(cls, args)

serverapp = cls.initialize_server(argv=args)

# Log if extension is blocking other extensions from loading.
Expand Down
6 changes: 6 additions & 0 deletions jupyter_server/tests/extension/mockextensions/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
mock_trait = Unicode('mock trait', config=True)
loaded = False

serverapp_config = {
"jpserver_extensions": {
"jupyter_server.tests.extension.mockextensions.mock1": True
}
}

@staticmethod
def get_extension_package():
return "jupyter_server.tests.extension.mockextensions"
Expand Down
12 changes: 12 additions & 0 deletions jupyter_server/tests/extension/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,15 @@ def test_extensionapp_load_config_file(
def test_browser_open(monkeypatch, jp_environ, config, expected_value):
serverapp = MockExtensionApp.initialize_server(config=Config(config))
assert serverapp.open_browser == expected_value



def test_load_parallel_extensions(monkeypatch, jp_environ):
serverapp = MockExtensionApp.initialize_server()
exts = serverapp.extension_manager.extensions
assert 'jupyter_server.tests.extension.mockextensions.mock1' in exts
assert 'jupyter_server.tests.extension.mockextensions' in exts

exts = serverapp.jpserver_extensions
assert exts['jupyter_server.tests.extension.mockextensions.mock1']
assert exts['jupyter_server.tests.extension.mockextensions']

0 comments on commit 0d11ffc

Please sign in to comment.