Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable extensions to set debug and open-browser flags #379

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ def get_extension_point(cls):

_log_formatter_cls = LogFormatter

# Whether this app is the starter app
_is_starter_app = False

@default('log_level')
def _default_log_level(self):
return logging.INFO
Expand Down Expand Up @@ -376,9 +379,8 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
# initializes it.
config = Config(cls._jupyter_server_config())
serverapp = ServerApp.instance(**kwargs, argv=[], config=config)
cls._is_starter_app = True
serverapp.initialize(argv=argv, find_extensions=load_other_extensions)
# Inform the serverapp that this extension app started the app.
serverapp._starter_app_name = cls.name
return serverapp

def initialize(self):
Expand Down Expand Up @@ -433,6 +435,8 @@ def _load_jupyter_server_extension(cls, serverapp):
except KeyError:
extension = cls()
extension._link_jupyter_server_extension(serverapp)
if cls._is_starter_app:
serverapp._starter_app = extension
extension.initialize()
return extension

Expand Down
24 changes: 15 additions & 9 deletions jupyter_server/serverapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,10 +517,19 @@ def start(self):
_("Allow the server to be run from root user.")
)
flags["no-browser"] = (
{"ServerApp": {"open_browser": False}},
{
"ServerApp": {"open_browser": False},
"ExtensionApp": {"open_browser": False}
},
_("Prevent the opening of the default url in the browser."),
)

flags["debug"] = (
{
'ServerApp': {'log_level': 'DEBUG'},
'ExtensionApp': {'log_level': 'DEBUG'}
},
_("Set debug level for the extension and underlying server applications.")
)
# Add notebook manager flags
flags.update(boolean_flag('script', 'FileContentsManager.save_script',
'DEPRECATED, IGNORED',
Expand Down Expand Up @@ -937,23 +946,20 @@ def _default_allow_remote(self):
# It is sometimes important to know if + which another app (say a server extension)
# started the serverapp to properly configure some traits.
# This trait should not be configured by users. It will likely be set by ExtensionApp.
_starter_app_name = Unicode(None, allow_none=True)
_starter_app = Instance(JupyterApp, allow_none=True)

@validate('_starter_app_name')
@validate('_starter_app')
def _validate_starter_app(self, proposal):
# Check that a previous server extension isn't named yet
value = proposal["value"]
if self._starter_app_name != None:
if self._starter_app != None:
raise TraitError("Another extension was already named as the starter_server_extension.")
return value

@property
def starter_app(self):
"""Get the Extension that started this server."""
name = self._starter_app_name
if name is None:
return
return self.extension_manager.extension_points.get(name, None).app
return self._starter_app

open_browser = Bool(False, config=True,
help="""Whether to open in a browser after starting.
Expand Down