From 34dce50bd79f3210b5ff81c3de3158dff27eb0de Mon Sep 17 00:00:00 2001
From: Gordon Ball <gordon@chronitis.net>
Date: Sat, 17 Dec 2016 16:46:56 +0100
Subject: Don't automatically import ipywidgets

ipywidgets.find_static_assets() is a no-op for ipywidgets > 4, which instead
use the nbextensions mechanism, but causes a warning to be shown if the
(redundant) widgetsnbextension package is not installed

Instead, a check is made whether the extensions.js file for the widgets is
available, and if not, a warning is shown advising the user of the deb
package to install
---
 notebook/notebookapp.py | 29 ++++++++++++++---------------
 1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py
index ab73020..7cef60f 100644
--- a/notebook/notebookapp.py
+++ b/notebook/notebookapp.py
@@ -233,24 +233,23 @@ class NotebookWebApplication(web.Application):
         handlers.extend(load_handlers('services.nbconvert.handlers'))
         handlers.extend(load_handlers('services.kernelspecs.handlers'))
         handlers.extend(load_handlers('services.security.handlers'))
-        
-        # BEGIN HARDCODED WIDGETS HACK
-        # TODO: Remove on notebook 5.0
+
+        # debian-specific
+        # check for installation of the ipywidgets server support, and advise how
+        # to install it if it's unavailable
+        # replaces a previous hardcoded attempt to import ipywidgets
+
+        deb_widgets_js = "/usr/share/jupyter/nbextensions/jupyter-js-widgets/extension.js"
+        has_widgetsnbextension = False
         try:
             import widgetsnbextension
+            has_widgetsnbextension = True
         except:
-            try:
-                import ipywidgets as widgets
-                handlers.append(
-                    (r"/nbextensions/widgets/(.*)", FileFindHandler, {
-                        'path': widgets.find_static_assets(),
-                        'no_cache_paths': ['/'], # don't cache anything in nbextensions
-                    }),
-                )
-            except:
-                app_log.warning('Widgets are unavailable. Please install widgetsnbextension or ipywidgets 4.0')
-        # END HARDCODED WIDGETS HACK
-        
+            pass
+
+        if not (os.path.exists(deb_widgets_js) or has_widgetsnbextension):
+            app_log.warning("Widgets are unavailable. On Debian, notebook support for widgets is provided by the package jupyter-nbextension-jupyter-js-widgets")
+
         handlers.append(
             (r"/nbextensions/(.*)", FileFindHandler, {
                 'path': settings['nbextensions_path'],
