Skip to content

Commit

Permalink
Merge pull request #1045 from ioam/backend_index_range_fix
Browse files Browse the repository at this point in the history
Fixed output magic message when backend unavailable
  • Loading branch information
jbednar authored Jan 10, 2017
2 parents 2425fad + 4405bb2 commit 642a604
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion holoviews/ipython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 14 additions & 3 deletions holoviews/ipython/magics.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,19 @@ 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)

custom_exceptions = {'holomap':missing_dependency_exception}
def missing_backend_exception(value, keyword, allowed):
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)

custom_exceptions = {'holomap':missing_dependency_exception,
'backend': missing_backend_exception }

# Counter for nbagg figures
nbagg_counter = 0
Expand Down Expand Up @@ -360,7 +368,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
Expand Down Expand Up @@ -392,7 +402,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)
Expand Down

0 comments on commit 642a604

Please sign in to comment.