Skip to content

Commit a86e123

Browse files
committed
pass serverapp to extension manager methods
1 parent e8e0f94 commit a86e123

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

jupyter_server/extension/application.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,16 @@ def _prepare_templates(self):
292292
self.initialize_templates()
293293

294294
@classmethod
295-
def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
296-
"""Creates an instance of ServerApp where this extension is enabled
297-
(superceding disabling found in other config from files).
298-
299-
This is necessary when launching the ExtensionApp directly from
300-
the `launch_instance` classmethod.
301-
"""
302-
# The ExtensionApp needs to add itself as enabled extension
303-
# to the jpserver_extensions trait, so that the ServerApp
304-
# initializes it.
305-
config = Config(cls._jupyter_server_config())
306-
serverapp = ServerApp.instance(**kwargs, argv=[], config=config)
307-
serverapp.initialize(argv=argv, find_extensions=load_other_extensions)
308-
return serverapp
295+
def _jupyter_server_config(cls):
296+
base_config = {
297+
"ServerApp": {
298+
"jpserver_extensions": {cls.get_extension_package(): True},
299+
"open_browser": True,
300+
"default_url": cls.extension_url
301+
}
302+
}
303+
base_config["ServerApp"].update(cls.server_config)
304+
return base_config
309305

310306
def _link_jupyter_server_extension(self, serverapp):
311307
"""Link the ExtensionApp to an initialized ServerApp.
@@ -335,6 +331,22 @@ def _link_jupyter_server_extension(self, serverapp):
335331
# i.e. ServerApp traits <--- ExtensionApp config
336332
self.serverapp.update_config(self.config)
337333

334+
@classmethod
335+
def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
336+
"""Creates an instance of ServerApp where this extension is enabled
337+
(superceding disabling found in other config from files).
338+
339+
This is necessary when launching the ExtensionApp directly from
340+
the `launch_instance` classmethod.
341+
"""
342+
# The ExtensionApp needs to add itself as enabled extension
343+
# to the jpserver_extensions trait, so that the ServerApp
344+
# initializes it.
345+
config = Config(cls._jupyter_server_config())
346+
serverapp = ServerApp.instance(**kwargs, argv=[], config=config)
347+
serverapp.initialize(argv=argv, find_extensions=load_other_extensions)
348+
return serverapp
349+
338350
def initialize(self):
339351
"""Initialize the extension app. The
340352
corresponding server app and webapp should already
@@ -374,18 +386,6 @@ def stop(self):
374386
self.serverapp.stop()
375387
self.serverapp.clear_instance()
376388

377-
@classmethod
378-
def _jupyter_server_config(cls):
379-
base_config = {
380-
"ServerApp": {
381-
"jpserver_extensions": {cls.get_extension_package(): True},
382-
"open_browser": True,
383-
"default_url": cls.extension_url
384-
}
385-
}
386-
base_config["ServerApp"].update(cls.server_config)
387-
return base_config
388-
389389
@classmethod
390390
def _load_jupyter_server_extension(cls, serverapp):
391391
"""Initialize and configure this extension, then add the extension's

jupyter_server/extension/manager.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,27 +215,27 @@ def extension_points(self):
215215
points.update(ext.extension_points)
216216
return points
217217

218-
def link_extensions(self):
218+
def link_extensions(self, serverapp):
219219
"""Link all enabled extensions
220220
to an instance of ServerApp
221221
"""
222222
# Sort the extension names to enforce deterministic linking
223223
# order.
224224
for name, ext in sorted(self.extension_points.items()):
225225
try:
226-
ext.link(self.parent)
226+
ext.link(serverapp)
227227
except Exception as e:
228228
self.log.warning(e)
229229

230-
def load_extensions(self):
230+
def load_extensions(self, serverapp):
231231
"""Load all enabled extensions and append them to
232232
the parent ServerApp.
233233
"""
234234
# Sort the extension names to enforce deterministic loading
235235
# order.
236236
for name, ext in sorted(self.extension_points.items()):
237237
try:
238-
ext.load(self.parent)
238+
ext.load(serverapp)
239239
except Exception as e:
240240
self.log.warning(e)
241241

jupyter_server/serverapp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ def init_server_extensions(self):
15141514
logger=self.log,
15151515
jpserver_extensions=self.jpserver_extensions
15161516
)
1517-
self.extension_manager.link_extensions()
1517+
self.extension_manager.link_extensions(self)
15181518

15191519
def load_server_extensions(self):
15201520
"""Load any extensions specified by config.
@@ -1524,7 +1524,7 @@ def load_server_extensions(self):
15241524
15251525
The extension API is experimental, and may change in future releases.
15261526
"""
1527-
self.extension_manager.load_extensions()
1527+
self.extension_manager.load_extensions(self)
15281528

15291529
def init_mime_overrides(self):
15301530
# On some Windows machines, an application has registered incorrect

0 commit comments

Comments
 (0)