Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.previous_backend = Store.current_backend
if not bokeh_renderer:
raise SkipTest("Bokeh required to test plot instantiation")
Store.current_backend = 'bokeh'
self.nbcontext = Renderer.notebook_context
Renderer.notebook_context = False
def setUp(self):
self.previous_backend = Store.current_backend
if not bokeh_renderer:
raise SkipTest("Bokeh required to test plot instantiation")
Store.current_backend = 'bokeh'
def test_apply_options_current_backend_plot_and_style(self):
obj = TestObj([]).options(style_opt1='A', plot_opt1='B')
plot_opts = Store.lookup_options('backend_1', obj, 'plot')
assert plot_opts.options == {'plot_opt1': 'B'}
style_opts = Store.lookup_options('backend_1', obj, 'style')
assert style_opts.options == {'style_opt1': 'A'}
Store.display_formats = p.display_formats
if 'html' not in p.display_formats and len(p.display_formats) > 1:
msg = ('Output magic unable to control displayed format '
'as IPython notebook uses fixed precedence '
'between %r' % p.display_formats)
display(HTML('<b>Warning</b>: %s' % msg))
loaded = notebook_extension._loaded
if loaded == False:
param_ext.load_ipython_extension(ip, verbose=False)
load_magics(ip)
Store.output_settings.initialize(list(Store.renderers.keys()))
Store.set_display_hook('html+js', LabelledData, pprint_display)
Store.set_display_hook('png', LabelledData, png_display)
Store.set_display_hook('svg', LabelledData, svg_display)
notebook_extension._loaded = True
css = ''
if p.width is not None:
css += '<style>div.container { width: %s%% }</style>' % p.width
if p.css:
css += '<style>%s</style>' % p.css
if css:
display(HTML(css))
resources = list(resources)
if len(resources) == 0: return
for r in [r for r in resources if r != 'holoviews']:
Store.renderers[r].load_nb(inline=p.inline)
try:
import pyparsing
except ImportError:
pyparsing = None
else:
from holoviews.util.parser import CompositorSpec
from holoviews.util.parser import OptsSpec
# Set to True to automatically run notebooks.
STORE_HISTORY = False
from IPython.core import page
InfoPrinter.store = Store
@magics_class
class OutputMagic(Magics):
@classmethod
def info(cls, obj):
disabled = Store.output_settings._disable_info_output
if Store.output_settings.options['info'] and not disabled:
page.page(InfoPrinter.info(obj, ansi=True))
@classmethod
def pprint(cls):
"""
Pretty print the current element options
"""
def cleanup_custom_options(id, weakref=None):
"""
Cleans up unused custom trees if all objects referencing the
custom id have been garbage collected or tree is otherwise
unreferenced.
"""
try:
if Store._options_context:
return
weakrefs = Store._weakrefs.get(id, [])
if weakref in weakrefs:
weakrefs.remove(weakref)
refs = []
for wr in list(weakrefs):
r = wr()
if r is None or r.id != id:
weakrefs.remove(wr)
else:
refs.append(r)
if not refs:
for bk in Store.loaded_backends():
if id in Store._custom_options[bk]:
Store._custom_options[bk].pop(id)
if not weakrefs:
def option_info(cls_or_slf, node):
if not cls_or_slf.show_options:
return None
from .options import Store, Options
options = {}
for g in Options._option_groups:
gopts = Store.lookup_options(Store.current_backend, node, g,
defaults=cls_or_slf.show_defaults)
if gopts:
options.update(gopts.kwargs)
opts = Options(**{k:v for k,v in options.items() if k != 'backend'})
return opts
if version_info[0] >= 4:
import nbformat # noqa (ensures availability)
else:
from IPython import nbformat # noqa (ensures availability)
try:
from .archive import notebook_archive
holoviews.archive = notebook_archive
except AttributeError as e:
if str(e) != "module 'tornado.web' has no attribute 'asynchronous'":
raise
except ImportError:
pass
# Not quite right, should be set when switching backends
if 'matplotlib' in Store.renderers and not notebook_extension._loaded:
svg_exporter = Store.renderers['matplotlib'].instance(holomap=None,fig='svg')
holoviews.archive.exporters = [svg_exporter] + holoviews.archive.exporters
p = param.ParamOverrides(self, {k:v for k,v in params.items() if k!='config'})
if p.case_sensitive_completion:
from IPython.core import completer
completer.completions_sorting_key = self.completions_sorting_key
if not p.allow_jedi_completion and hasattr(IPCompleter, 'use_jedi'):
ip.run_line_magic('config', 'IPCompleter.use_jedi = False')
resources = self._get_resources(args, params)
Store.display_formats = p.display_formats
if 'html' not in p.display_formats and len(p.display_formats) > 1:
msg = ('Output magic unable to control displayed format '
'as IPython notebook uses fixed precedence '
def _repr_mimebundle_(self, include=None, exclude=None):
"""
Resolves the class hierarchy for the class rendering the
object using any display hooks registered on Store.display
hooks. The output of all registered display_hooks is then
combined and returned.
"""
return Store.render(self)
def element_display(element, max_frames):
info = process_object(element)
if info:
display(HTML(info))
return
backend = Store.current_backend
if type(element) not in Store.registry[backend]:
return None
return render(element)