Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow defining hooks on backend load #3429

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"""
cls._backend_hooks[backend].append(callback)


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