Skip to content

Commit 2ca90fa

Browse files
committed
🍰 Got the new JS deprecation warning working
1 parent fac424e commit 2ca90fa

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

jupyter_notebook/notebookapp.py

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,17 @@ def load_handlers(name):
119119
name = 'jupyter_notebook.' + name
120120
mod = __import__(name, fromlist=['default_handlers'])
121121
return mod.default_handlers
122-
122+
123+
124+
class DeprecationHandler(IPythonHandler):
125+
def get(self, url_path):
126+
self.set_header("Content-Type", 'text/javascript')
127+
self.finish("""
128+
console.warn('`/static/widgets/js` is deprecated. Use `/nbextensions/widgets/widgets/js` instead.');
129+
define(['%s'], function(x) { return x; });
130+
""" % url_path_join('nbextensions', 'widgets', 'widgets', url_path.rstrip('.js')))
131+
self.log.warn('Deprecated widget Javascript path /static/widgets/js/*.js was used')
132+
123133
#-----------------------------------------------------------------------------
124134
# The Tornado web application
125135
#-----------------------------------------------------------------------------
@@ -131,7 +141,6 @@ def __init__(self, ipython_app, kernel_manager, contents_manager,
131141
config_manager, log,
132142
base_url, default_url, settings_overrides, jinja_env_options):
133143

134-
self.log = log
135144
settings = self.init_settings(
136145
ipython_app, kernel_manager, contents_manager, cluster_manager,
137146
session_manager, kernel_spec_manager, config_manager, log, base_url,
@@ -145,6 +154,7 @@ def init_settings(self, ipython_app, kernel_manager, contents_manager,
145154
config_manager,
146155
log, base_url, default_url, settings_overrides,
147156
jinja_env_options=None):
157+
148158
_template_path = settings_overrides.get(
149159
"template_path",
150160
ipython_app.template_file_path,
@@ -214,7 +224,7 @@ def init_handlers(self, settings):
214224

215225
# Order matters. The first handler to match the URL will handle the request.
216226
handlers = []
217-
handlers.extend(self._create_widget_shim_handlers(settings))
227+
handlers.append((r'/deprecatedwidgets/(.*)', DeprecationHandler))
218228
handlers.extend(load_handlers('tree.handlers'))
219229
handlers.extend([(r"/login", settings['login_handler_class'])])
220230
handlers.extend([(r"/logout", settings['logout_handler_class'])])
@@ -263,22 +273,6 @@ def init_handlers(self, settings):
263273
new_handlers.append((r'(.*)', Template404))
264274
return new_handlers
265275

266-
def _create_widget_shim_handlers(self, settings):
267-
"""Creates a handler that shims the loading of widgets
268-
JS files for the old /static/widgets/js/*.js path."""
269-
class DeprecationHandler(IPythonHandler):
270-
def get(self, url_path):
271-
self.set_header("Content-Type", 'text/javascript')
272-
self.finish("""
273-
console.warn('`/static/widgets/js` is deprecated. Use `/nbextensions/widgets/widgets/js` instead.');
274-
define(['%s'], function(x) { console.log('...loaded...'); return x; });
275-
""" % url_path_join(settings['base_url'], 'nbextensions', 'widgets', 'widgets', url_path))
276-
self.log.warn('Deprecated widget Javascript path /static/widgets/js/*.js was used')
277-
return [(
278-
r'/deprecatedwidgets/(.*)',
279-
DeprecationHandler
280-
)]
281-
282276

283277
class NbserverListApp(JupyterApp):
284278

0 commit comments

Comments
 (0)