From cb040fddb5f4cfe336ee696acdd880406b808503 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 10 Jan 2017 17:23:09 +0000 Subject: [PATCH 1/4] Fixed output magic message when backend unavailable --- holoviews/ipython/magics.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index 30ee6c7349..1bb9406681 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -360,7 +360,9 @@ def update_options(cls, options, items): prev_backend = Store.current_backend renderer = Store.renderers[Store.current_backend] prev_backend += ':%s' % renderer.mode - if not backend or backend == prev_backend: + + available = backend in Store.renderers.keys() + if (not backend) or (not available) or backend == prev_backend: return options cls._backend_options[prev_backend] = cls.options From c63cc9a2b62e00312df03e80ffa3fe4e787c004b Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 10 Jan 2017 17:37:09 +0000 Subject: [PATCH 2/4] Set custom exception message for backend selection error --- holoviews/ipython/magics.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index 1bb9406681..a54a6abbd9 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -260,7 +260,11 @@ class OutputMagic(OptionsMagic): def missing_dependency_exception(value, keyword, allowed): raise Exception("Format %r does not appear to be supported." % value) - custom_exceptions = {'holomap':missing_dependency_exception} + def missing_backend_exception(value, keyword, allowed): + raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) + + custom_exceptions = {'holomap':missing_dependency_exception, + 'backend': missing_backend_exception } # Counter for nbagg figures nbagg_counter = 0 From 93f922aae9db3d8932a0c1c102357d83299dba16 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 10 Jan 2017 19:50:56 +0000 Subject: [PATCH 3/4] Further improved quality of error message for invalid backends --- holoviews/ipython/__init__.py | 2 +- holoviews/ipython/magics.py | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/holoviews/ipython/__init__.py b/holoviews/ipython/__init__.py index 188a06ed04..e2e2df089c 100644 --- a/holoviews/ipython/__init__.py +++ b/holoviews/ipython/__init__.py @@ -186,7 +186,7 @@ def __call__(self, *args, **params): ip = get_ipython() if ip is None else ip # noqa (get_ipython) param_ext.load_ipython_extension(ip, verbose=False) load_magics(ip) - OutputMagic.initialize() + OutputMagic.initialize(list( self._backends.keys())) set_display_hooks(ip) notebook_extension._loaded = True diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index a54a6abbd9..125ac996b9 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -256,12 +256,20 @@ class OutputMagic(OptionsMagic): #==========================# last_backend = None + backend_list = [] # List of possible backends def missing_dependency_exception(value, keyword, allowed): raise Exception("Format %r does not appear to be supported." % value) def missing_backend_exception(value, keyword, allowed): - raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) + if value in OutputMagic.backend_list: + raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) + else: + raise ValueError("Backend %r does not exist" % value) + + + raise ValueError(OutputMagic.backend_list, value) + # raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) custom_exceptions = {'holomap':missing_dependency_exception, 'backend': missing_backend_exception } @@ -398,7 +406,8 @@ def update_options(cls, options, items): @classmethod - def initialize(cls): + def initialize(cls, backend_list): + cls.backend_list = backend_list backend = cls.options.get('backend', cls.defaults['backend']) if backend in Store.renderers: cls.options = dict(cls.defaults) From 4405bb22b43efe14d47625d36b56abf30ea25693 Mon Sep 17 00:00:00 2001 From: jlstevens Date: Tue, 10 Jan 2017 19:53:25 +0000 Subject: [PATCH 4/4] Removed stray comment --- holoviews/ipython/magics.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/holoviews/ipython/magics.py b/holoviews/ipython/magics.py index 125ac996b9..894510f76e 100644 --- a/holoviews/ipython/magics.py +++ b/holoviews/ipython/magics.py @@ -267,10 +267,6 @@ def missing_backend_exception(value, keyword, allowed): else: raise ValueError("Backend %r does not exist" % value) - - raise ValueError(OutputMagic.backend_list, value) - # raise ValueError("Backend %r not available. Has it been loaded with the notebook_extension?" % value) - custom_exceptions = {'holomap':missing_dependency_exception, 'backend': missing_backend_exception }