Skip to content

Commit 2f02e93

Browse files
authored
Merge pull request #213 from datalayer-contrib/load-warning-message2
Nested try/except on _load_jupyter_server_extension discovery
2 parents 7dbc701 + fd04222 commit 2f02e93

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

jupyter_server/serverapp.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,31 +1605,34 @@ def load_server_extensions(self):
16051605
"loaded".format(extension_name=extension.extension_name)
16061606
)
16071607
# Find the extension loading function.
1608+
func = None
16081609
try:
16091610
# This function was prefixed with an underscore in in v1.0
16101611
# because this shouldn't be a public API for most extensions.
16111612
func = getattr(extension, '_load_jupyter_server_extension')
1612-
func(self)
1613-
self.log.debug(log_msg)
16141613
except AttributeError:
1615-
# For backwards compatibility, we will still look for non
1616-
# underscored loading functions.
1617-
func = getattr(extension, 'load_jupyter_server_extension')
1614+
try:
1615+
# For backwards compatibility, we will still look for non
1616+
# underscored loading functions.
1617+
func = getattr(extension, 'load_jupyter_server_extension')
1618+
warn_msg = _(
1619+
"{extkey} is enabled. "
1620+
"`load_jupyter_server_extension` function "
1621+
"was found but `_load_jupyter_server_extension`"
1622+
"is preferred.".format(extkey=extkey)
1623+
)
1624+
self.log.warning(warn_msg)
1625+
except AttributeError:
1626+
warn_msg = _(
1627+
"{extkey} is enabled but no "
1628+
"`_load_jupyter_server_extension` function "
1629+
"was found.".format(extkey=extkey)
1630+
)
1631+
self.log.warning(warn_msg)
1632+
if func:
16181633
func(self)
1619-
warn_msg = _(
1620-
"{extkey} is enabled. "
1621-
"`load_jupyter_server_extension` function "
1622-
"was found but `_load_jupyter_server_extension`"
1623-
"is preferred.".format(extkey=extkey)
1624-
)
1625-
self.log.warning(warn_msg)
1626-
except AttributeError:
1627-
warn_msg = _(
1628-
"{extkey} is enabled but no "
1629-
"`_load_jupyter_server_extension` function "
1630-
"was found.".format(extkey=extkey)
1631-
)
1632-
self.log.warning(warn_msg)
1634+
self.log.debug(log_msg)
1635+
16331636

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

0 commit comments

Comments
 (0)