Skip to content

Commit 5668d7e

Browse files
committed
change extension name back to name
1 parent 9755840 commit 5668d7e

File tree

5 files changed

+43
-65
lines changed

5 files changed

+43
-65
lines changed

jupyter_server/extension/application.py

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _prepare_templates(self):
9696
# Add templates to web app settings if extension has templates.
9797
if len(self.template_paths) > 0:
9898
self.settings.update({
99-
"{}_template_paths".format(self.extension_name): self.template_paths
99+
"{}_template_paths".format(self.name): self.template_paths
100100
})
101101

102102
# Create a jinja environment for logging html templates.
@@ -111,7 +111,7 @@ def _prepare_templates(self):
111111
# Add the jinja2 environment for this extension to the tornado settings.
112112
self.settings.update(
113113
{
114-
"{}_jinja2_env".format(self.extension_name): self.jinja2_env
114+
"{}_jinja2_env".format(self.name): self.jinja2_env
115115
}
116116
)
117117

@@ -144,32 +144,11 @@ class method. This method can be set as a entry_point in
144144
# side-by-side when launched directly.
145145
load_other_extensions = True
146146

147-
# Name of the extension
148-
extension_name = Unicode(
149-
help="Name of extension."
150-
)
151-
152-
@default('extension_name')
153-
def _extension_name_default(self):
154-
try:
155-
return self.name
156-
except AttributeError:
157-
raise ValueError("The extension must be given a `name`.")
158-
159-
INVALID_EXTENSION_NAME_CHARS = [' ', '.', '+', '/']
160-
161-
@validate('extension_name')
162-
def _validate_extension_name(self, proposal):
163-
value = proposal['value']
164-
if isinstance(value, str):
165-
# Validate that extension_name doesn't contain any invalid characters.
166-
for c in ExtensionApp.INVALID_EXTENSION_NAME_CHARS:
167-
if c in value:
168-
raise ValueError("Extension name '{name}' cannot contain any of the following characters: "
169-
"{invalid_chars}.".
170-
format(name=value, invalid_chars=ExtensionApp.INVALID_EXTENSION_NAME_CHARS))
171-
return value
172-
raise ValueError("Extension name must be a string, found {type}.".format(type=type(value)))
147+
# The extension name used to name the jupyter config
148+
# file, jupyter_{name}_config.
149+
# This should also match the jupyter subcommand used to launch
150+
# this extension from the CLI, e.g. `jupyter {name}`.
151+
name = None
173152

174153
# Extension URL sets the default landing page for this extension.
175154
extension_url = "/"
@@ -181,8 +160,8 @@ def _validate_extension_name(self, proposal):
181160

182161
@property
183162
def static_url_prefix(self):
184-
return "/static/{extension_name}/".format(
185-
extension_name=self.extension_name)
163+
return "/static/{name}/".format(
164+
name=self.name)
186165

187166
static_paths = List(Unicode(),
188167
help="""paths to search for serving static files.
@@ -216,10 +195,9 @@ def static_url_prefix(self):
216195

217196
def _config_file_name_default(self):
218197
"""The default config file name."""
219-
if not self.extension_name:
198+
if not self.name:
220199
return ''
221-
return 'jupyter_{}_config'.format(self.extension_name.replace('-','_'))
222-
200+
return 'jupyter_{}_config'.format(self.name.replace('-','_'))
223201

224202
def initialize_settings(self):
225203
"""Override this method to add handling of settings."""
@@ -235,11 +213,11 @@ def initialize_templates(self):
235213

236214
def _prepare_config(self):
237215
"""Builds a Config object from the extension's traits and passes
238-
the object to the webapp's settings as `<extension_name>_config`.
216+
the object to the webapp's settings as `<name>_config`.
239217
"""
240218
traits = self.class_own_traits().keys()
241219
self.extension_config = Config({t: getattr(self, t) for t in traits})
242-
self.settings['{}_config'.format(self.extension_name)] = self.extension_config
220+
self.settings['{}_config'.format(self.name)] = self.extension_config
243221

244222
def _prepare_settings(self):
245223
# Make webapp settings accessible to initialize_settings method
@@ -248,8 +226,8 @@ def _prepare_settings(self):
248226

249227
# Add static and template paths to settings.
250228
self.settings.update({
251-
"{}_static_paths".format(self.extension_name): self.static_paths,
252-
"{}".format(self.extension_name): self
229+
"{}_static_paths".format(self.name): self.static_paths,
230+
"{}".format(self.name): self
253231
})
254232

255233
# Get setting defined by subclass using initialize_settings method.
@@ -274,7 +252,8 @@ def _prepare_handlers(self):
274252
# Get handler kwargs, if given
275253
kwargs = {}
276254
if issubclass(handler, ExtensionHandlerMixin):
277-
kwargs['extension_name'] = self.extension_name
255+
kwargs['name'] = self.name
256+
278257
try:
279258
kwargs.update(handler_items[2])
280259
except IndexError:
@@ -302,7 +281,7 @@ def _prepare_templates(self):
302281
# Add templates to web app settings if extension has templates.
303282
if len(self.template_paths) > 0:
304283
self.settings.update({
305-
"{}_template_paths".format(self.extension_name): self.template_paths
284+
"{}_template_paths".format(self.name): self.template_paths
306285
})
307286
self.initialize_templates()
308287

@@ -319,7 +298,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
319298
# initializes it.
320299
config = Config({
321300
"ServerApp": {
322-
"jpserver_extensions": {cls.extension_name: True},
301+
"jpserver_extensions": {cls.name: True},
323302
"open_browser": cls.open_browser,
324303
"default_url": cls.extension_url
325304
}
@@ -402,7 +381,7 @@ def _load_jupyter_server_extension(cls, serverapp):
402381
"""
403382
try:
404383
# Get loaded extension from serverapp.
405-
extension = serverapp._enabled_extensions[cls.extension_name]
384+
extension = serverapp._enabled_extensions[cls.name]
406385
except KeyError:
407386
extension = cls()
408387
extension.link_to_serverapp(serverapp)
@@ -438,6 +417,6 @@ def launch_instance(cls, argv=None, **kwargs):
438417
if not cls.load_other_extensions:
439418
serverapp.log.info(
440419
"{ext_name} is running without loading "
441-
"other extensions.".format(ext_name=cls.extension_name)
420+
"other extensions.".format(ext_name=cls.name)
442421
)
443422
serverapp.start()

jupyter_server/extension/handler.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,26 @@ class ExtensionHandlerJinjaMixin:
88
"""
99
def get_template(self, name):
1010
"""Return the jinja template object for a given name"""
11-
env = '{}_jinja2_env'.format(self.extension_name)
11+
env = '{}_jinja2_env'.format(self.name)
1212
return self.settings[env].get_template(name)
1313

1414

1515
class ExtensionHandlerMixin:
1616
"""Base class for Jupyter server extension handlers.
1717
1818
Subclasses can serve static files behind a namespaced
19-
endpoint: "/static/<extension_name>/"
19+
endpoint: "/static/<name>/"
2020
2121
This allows multiple extensions to serve static files under
2222
their own namespace and avoid intercepting requests for
2323
other extensions.
2424
"""
25-
def initialize(self, extension_name):
26-
self.extension_name = extension_name
25+
def initialize(self, name):
26+
self.name = name
2727

2828
@property
2929
def extensionapp(self):
30-
return self.settings[self.extension_name]
30+
return self.settings[self.name]
3131

3232
@property
3333
def serverapp(self):
@@ -36,24 +36,23 @@ def serverapp(self):
3636

3737
@property
3838
def config(self):
39-
return self.settings["{}_config".format(self.extension_name)]
39+
return self.settings["{}_config".format(self.name)]
4040

4141
@property
4242
def server_config(self):
4343
return self.settings["config"]
4444

4545
@property
4646
def static_url_prefix(self):
47-
return "/static/{extension_name}/".format(
48-
extension_name=self.extension_name)
47+
return "/static/{name}/".format(name=self.name)
4948

5049
@property
5150
def static_path(self):
52-
return self.settings['{}_static_paths'.format(self.extension_name)]
51+
return self.settings['{}_static_paths'.format(self.name)]
5352

5453
def static_url(self, path, include_host=None, **kwargs):
5554
"""Returns a static URL for the given relative static file path.
56-
This method requires you set the ``{extension_name}_static_path``
55+
This method requires you set the ``{name}_static_path``
5756
setting in your extension (which specifies the root directory
5857
of your static files).
5958
This method returns a versioned url (by default appending
@@ -68,7 +67,7 @@ def static_url(self, path, include_host=None, **kwargs):
6867
that value will be used as the default for all `static_url`
6968
calls that do not pass ``include_host`` as a keyword argument.
7069
"""
71-
key = "{}_static_paths".format(self.extension_name)
70+
key = "{}_static_paths".format(self.name)
7271
try:
7372
self.require_setting(key, "static_url")
7473
except Exception as e:

jupyter_server/extension/serverextension.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _get_load_jupyter_server_extension(obj):
154154
return func
155155

156156

157-
def validate_server_extension(extension_name):
157+
def validate_server_extension(name):
158158
"""Validates that you can import the extension module,
159159
gather all extension metadata, and find `load_jupyter_server_extension`
160160
functions for each extension.
@@ -176,10 +176,10 @@ def validate_server_extension(extension_name):
176176
"""
177177
# If the extension does not exist, raise an exception
178178
try:
179-
mod, metadata = _get_server_extension_metadata(extension_name)
179+
mod, metadata = _get_server_extension_metadata(name)
180180
version = getattr(mod, '__version__', '')
181181
except ImportError:
182-
raise ExtensionValidationError('{} is not importable.'.format(extension_name))
182+
raise ExtensionValidationError('{} is not importable.'.format(name))
183183

184184
try:
185185
for item in metadata:
@@ -194,7 +194,7 @@ def validate_server_extension(extension_name):
194194
raise AttributeError
195195
# If the extension does not have a `load_jupyter_server_extension` function, raise exception.
196196
except AttributeError:
197-
raise ExtensionValidationError('Found "{}" module but cannot load it.'.format(extension_name))
197+
raise ExtensionValidationError('Found "{}" module but cannot load it.'.format(name))
198198
return version
199199

200200

jupyter_server/serverapp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ def init_server_extensions(self):
15711571
app = extapp()
15721572
app.link_to_serverapp(self)
15731573
# Build a new list where we
1574-
self._enabled_extensions[app.extension_name] = app
1574+
self._enabled_extensions[app.name] = app
15751575
elif extloc:
15761576
extmod = importlib.import_module(extloc)
15771577
func = _get_load_jupyter_server_extension(extmod)
@@ -1603,8 +1603,8 @@ def load_server_extensions(self):
16031603
)
16041604
else:
16051605
log_msg = (
1606-
"Extension {extension_name} enabled and "
1607-
"loaded".format(extension_name=extension.extension_name)
1606+
"Extension {name} enabled and "
1607+
"loaded".format(name=extension.name)
16081608
)
16091609
# Find the extension loading function.
16101610
func = None

tests/extension/mockextensions/app.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ def get(self):
1818

1919

2020
class MockExtensionTemplateHandler(
21-
ExtensionHandlerJinjaMixin,
22-
ExtensionHandlerMixin,
23-
JupyterHandler
24-
):
21+
ExtensionHandlerJinjaMixin,
22+
ExtensionHandlerMixin,
23+
JupyterHandler
24+
):
2525

2626
def get(self):
2727
self.write(self.render_template("index.html"))
2828

2929

3030
class MockExtensionApp(ExtensionAppJinjaMixin, ExtensionApp):
3131

32-
extension_name = 'mockextension'
32+
name = 'mockextension'
3333
template_paths = List().tag(config=True)
3434
mock_trait = Unicode('mock trait', config=True)
3535
loaded = False

0 commit comments

Comments
 (0)