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

[MRG] Pass extension configuration to extension handlers #59

Merged
merged 2 commits into from
Jun 27, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions jupyter_server/extension/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
default,
validate
)
from traitlets.config import Config

from jupyter_core.application import JupyterApp

Expand Down Expand Up @@ -141,6 +142,14 @@ def initialize_templates(self):
"""Override this method to add handling of template files."""
pass

def _prepare_config(self):
"""Builds a Config object from the extension's traits and passes
the object to the webapp's settings as `<extension_name>_config`.
"""
traits = self.class_own_traits().keys()
config = Config({t: getattr(self, t) for t in traits})
self.settings['{}_config'.format(self.extension_name)] = config

def _prepare_settings(self):
# Make webapp settings accessible to initialize_settings method
webapp = self.serverapp.web_app
Expand Down Expand Up @@ -280,6 +289,7 @@ def load_jupyter_server_extension(cls, serverapp, argv=None, **kwargs):
extension.initialize(serverapp, argv=argv)

# Initialize extension template, settings, and handlers.
extension._prepare_config()
extension._prepare_templates()
extension._prepare_settings()
extension._prepare_handlers()
Expand Down
4 changes: 4 additions & 0 deletions jupyter_server/extension/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def initialize(self, extension_name, **kwargs):
self.extension_name = extension_name
super(ExtensionHandler, self).initialize(**kwargs)

@property
def config(self):
return self.settings["{}_config".format(self.extension_name)]

@property
def static_url_prefix(self):
return "/static/{extension_name}/".format(
Expand Down