@@ -96,7 +96,7 @@ def _prepare_templates(self):
96
96
# Add templates to web app settings if extension has templates.
97
97
if len (self .template_paths ) > 0 :
98
98
self .settings .update ({
99
- "{}_template_paths" .format (self .extension_name ): self .template_paths
99
+ "{}_template_paths" .format (self .name ): self .template_paths
100
100
})
101
101
102
102
# Create a jinja environment for logging html templates.
@@ -111,7 +111,7 @@ def _prepare_templates(self):
111
111
# Add the jinja2 environment for this extension to the tornado settings.
112
112
self .settings .update (
113
113
{
114
- "{}_jinja2_env" .format (self .extension_name ): self .jinja2_env
114
+ "{}_jinja2_env" .format (self .name ): self .jinja2_env
115
115
}
116
116
)
117
117
@@ -144,32 +144,11 @@ class method. This method can be set as a entry_point in
144
144
# side-by-side when launched directly.
145
145
load_other_extensions = True
146
146
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
173
152
174
153
# Extension URL sets the default landing page for this extension.
175
154
extension_url = "/"
@@ -181,8 +160,8 @@ def _validate_extension_name(self, proposal):
181
160
182
161
@property
183
162
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 )
186
165
187
166
static_paths = List (Unicode (),
188
167
help = """paths to search for serving static files.
@@ -216,10 +195,9 @@ def static_url_prefix(self):
216
195
217
196
def _config_file_name_default (self ):
218
197
"""The default config file name."""
219
- if not self .extension_name :
198
+ if not self .name :
220
199
return ''
221
- return 'jupyter_{}_config' .format (self .extension_name .replace ('-' ,'_' ))
222
-
200
+ return 'jupyter_{}_config' .format (self .name .replace ('-' ,'_' ))
223
201
224
202
def initialize_settings (self ):
225
203
"""Override this method to add handling of settings."""
@@ -235,11 +213,11 @@ def initialize_templates(self):
235
213
236
214
def _prepare_config (self ):
237
215
"""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`.
239
217
"""
240
218
traits = self .class_own_traits ().keys ()
241
219
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
243
221
244
222
def _prepare_settings (self ):
245
223
# Make webapp settings accessible to initialize_settings method
@@ -248,8 +226,8 @@ def _prepare_settings(self):
248
226
249
227
# Add static and template paths to settings.
250
228
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
253
231
})
254
232
255
233
# Get setting defined by subclass using initialize_settings method.
@@ -274,7 +252,8 @@ def _prepare_handlers(self):
274
252
# Get handler kwargs, if given
275
253
kwargs = {}
276
254
if issubclass (handler , ExtensionHandlerMixin ):
277
- kwargs ['extension_name' ] = self .extension_name
255
+ kwargs ['name' ] = self .name
256
+
278
257
try :
279
258
kwargs .update (handler_items [2 ])
280
259
except IndexError :
@@ -302,7 +281,7 @@ def _prepare_templates(self):
302
281
# Add templates to web app settings if extension has templates.
303
282
if len (self .template_paths ) > 0 :
304
283
self .settings .update ({
305
- "{}_template_paths" .format (self .extension_name ): self .template_paths
284
+ "{}_template_paths" .format (self .name ): self .template_paths
306
285
})
307
286
self .initialize_templates ()
308
287
@@ -319,7 +298,7 @@ def initialize_server(cls, argv=[], load_other_extensions=True, **kwargs):
319
298
# initializes it.
320
299
config = Config ({
321
300
"ServerApp" : {
322
- "jpserver_extensions" : {cls .extension_name : True },
301
+ "jpserver_extensions" : {cls .name : True },
323
302
"open_browser" : cls .open_browser ,
324
303
"default_url" : cls .extension_url
325
304
}
@@ -402,7 +381,7 @@ def _load_jupyter_server_extension(cls, serverapp):
402
381
"""
403
382
try :
404
383
# Get loaded extension from serverapp.
405
- extension = serverapp ._enabled_extensions [cls .extension_name ]
384
+ extension = serverapp ._enabled_extensions [cls .name ]
406
385
except KeyError :
407
386
extension = cls ()
408
387
extension .link_to_serverapp (serverapp )
@@ -438,6 +417,6 @@ def launch_instance(cls, argv=None, **kwargs):
438
417
if not cls .load_other_extensions :
439
418
serverapp .log .info (
440
419
"{ext_name} is running without loading "
441
- "other extensions." .format (ext_name = cls .extension_name )
420
+ "other extensions." .format (ext_name = cls .name )
442
421
)
443
422
serverapp .start ()
0 commit comments