Skip to content

Commit

Permalink
Allow defining hooks on backend load
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 25, 2019
1 parent 7dbb05d commit 3da79a1
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions holoviews/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os, sys, inspect, shutil

from collections import defaultdict

import param
from pyviz_comms import extension as _pyviz_extension

Expand Down Expand Up @@ -576,6 +578,9 @@ class extension(_pyviz_extension):
'bokeh': 'bokeh',
'plotly': 'plotly'}

# Hooks run when a backend is loaded
_backend_hooks = defaultdict(list)

def __call__(self, *args, **params):
# Get requested backends
config = params.pop('config', {})
Expand Down Expand Up @@ -616,11 +621,23 @@ def __call__(self, *args, **params):
Store.output_settings.allowed['backend'] = list_backends()
Store.output_settings.allowed['fig'] = list_formats('fig', backend)
Store.output_settings.allowed['holomap'] = list_formats('holomap', backend)
for hook in self._backend_hooks[backend]:
try:
hook()
except Exception as e:
self.param.warning('%s backend hook %s failed with '
'following exception: %s' %
(backend, hook, e))

if selected_backend is None:
raise ImportError('None of the backends could be imported')
Store.set_current_backend(selected_backend)

@classmethod
def register_backend_callback(cls, backend, callback):
"""Registers a hook which is run when a backend is loaded"""
self._backend_hooks[backend].append(callback)


def save(obj, filename, fmt='auto', backend=None, **kwargs):
"""
Expand Down

0 comments on commit 3da79a1

Please sign in to comment.