def test_with_INLINE_resources(self) -> None: from latex_label import LatexLabel plot = Plot() plot.add_layout(LatexLabel()) bundle = beb.bundle_for_objs_and_resources([plot], "inline") assert len(bundle.js_raw) == 3 assert "class LatexLabelView" in bundle.js_raw[2]
async def get(self, *args, **kwargs): session = await self.get_session() element_id = self.get_argument("bokeh-autoload-element", default=None) if not element_id: self.send_error(status_code=400, reason='No bokeh-autoload-element query parameter') return app_path = self.get_argument("bokeh-app-path", default="/") absolute_url = self.get_argument("bokeh-absolute-url", default=None) if absolute_url: server_url = '{uri.scheme}://{uri.netloc}'.format(uri=urlparse(absolute_url)) else: server_url = None resources_param = self.get_argument("resources", "default") resources = self.application.resources(server_url) if resources_param != "none" else None bundle = bundle_for_objs_and_resources(None, resources) render_items = [RenderItem(sessionid=session.id, elementid=element_id, use_for_title=False)] bundle.add(Script(script_for_render_items(None, render_items, app_path=app_path, absolute_url=absolute_url))) js = AUTOLOAD_JS.render(bundle=bundle, elementid=element_id) self.set_header("Content-Type", 'application/javascript') self.write(js)
def test_with_CDN_resources(self) -> None: from latex_label import LatexLabel plot = Plot() plot.add_layout(LatexLabel()) bundle = beb.bundle_for_objs_and_resources([plot], "cdn") assert len(bundle.js_files) == 2 assert bundle.js_files[1] == "https://unpkg.com/latex_label@^0.0.1/dist/latex_label.js"
async def handle(self, body: bytes) -> None: session = await self._get_session() element_id = self.get_argument("bokeh-autoload-element", default=None) if not element_id: raise RuntimeError("No bokeh-autoload-element query parameter") app_path = self.get_argument("bokeh-app-path", default="/") absolute_url = self.get_argument("bokeh-absolute-url", default=None) server_url: Optional[str] if absolute_url: server_url = '{uri.scheme}://{uri.netloc}/'.format(uri=urlparse(absolute_url)) else: server_url = None resources_param = self.get_argument("resources", "default") resources = self.resources(server_url) if resources_param != "none" else None bundle = bundle_for_objs_and_resources(None, resources) render_items = [RenderItem(sessionid=session.id, elementid=element_id, use_for_title=False)] bundle.add(Script(script_for_render_items(None, render_items, app_path=app_path, absolute_url=absolute_url))) js = AUTOLOAD_JS.render(bundle=bundle, elementid=element_id) await self.send_response(200, js.encode(), headers=[(b"Content-Type", b"application/javascript")])
def test_with_Server_resources(self) -> None: from latex_label import LatexLabel plot = Plot() plot.add_layout(LatexLabel()) bundle = beb.bundle_for_objs_and_resources([plot], "server") assert len(bundle.js_files) == 2 assert bundle.js_files[1] == "http://localhost:5006/static/extensions/latex_label/latex_label.js"
def load_notebook(inline=True, load_timeout=5000): from IPython.display import publish_display_data resources = INLINE if inline else CDN prev_resources = settings.resources(default="server") user_resources = settings.resources._user_value is not _Unset try: settings.resources = 'inline' if inline else 'cdn' bundle = bundle_for_objs_and_resources(None, resources) configs, requirements, exports, skip_imports = require_components() ipywidget = 'ipywidgets_bokeh' in sys.modules bokeh_js = _autoload_js(bundle, configs, requirements, exports, skip_imports, ipywidget, load_timeout) finally: if user_resources: settings.resources = prev_resources else: settings.resources.unset_value() publish_display_data({ 'application/javascript': bokeh_js, LOAD_MIME: bokeh_js, }) bokeh.io.notebook.curstate().output_notebook() # Publish comm manager JS = '\n'.join([PYVIZ_PROXY, _JupyterCommManager.js_manager, nb_mime_js]) publish_display_data(data={LOAD_MIME: JS, 'application/javascript': JS})
def file_html(models, resources, title=None, template=BASE_TEMPLATE, template_variables={}, theme=None, _always_new=False): models_seq = [] if isinstance(models, Model): models_seq = [models] elif isinstance(models, Document): models_seq = models.roots else: models_seq = models with OutputDocumentFor(models_seq, apply_theme=theme, always_new=_always_new): (docs_json, render_items) = standalone_docs_json_and_render_items( models_seq, suppress_callback_warning=True) title = _title_from_models(models_seq, title) bundle = bundle_for_objs_and_resources(None, resources) bundle = Bundle.from_bokeh(bundle) return html_page_for_render_items( bundle, docs_json, render_items, title=title, template=template, template_variables=template_variables)
def test_with_Server_resources_dev(self) -> None: from latex_label import LatexLabel plot = Plot() plot.add_layout(LatexLabel()) with envset(BOKEH_RESOURCES="server", BOKEH_DEV="true"): bundle = beb.bundle_for_objs_and_resources([plot], "server") assert len(bundle.js_files) == 2 assert bundle.js_files[1] == "http://localhost:5006/static/extensions/latex_label/latex_label.js"
def test_with_Server_resources(self) -> None: from latex_label import LatexLabel plot = Plot() plot.add_layout(LatexLabel()) bundle = beb.bundle_for_objs_and_resources([plot], "server") version_hash = "6b13789e43e5485634533de16a65d8ba9d34c4c9758588b665805435f80eb115" assert len(bundle.js_files) == 2 assert (bundle.js_files[1] == f"http://localhost:5006/static/extensions/latex_label/latex_label.js?v={version_hash}")
def test_env_vars_precedence(self) -> None: b = beb.bundle_for_objs_and_resources([], INLINE) assert all('localhost' not in x for x in b.js_files) # this is a cheap test that a BokehJS file is inline assert any(len(x) > 5000 for x in b.js_raw) with envset(BOKEH_RESOURCES="server-dev"): b = beb.bundle_for_objs_and_resources([], INLINE) assert any('localhost' in x for x in b.js_files) # this is a cheap test that a BokehJS file is NOT inline assert all(len(x) < 5000 for x in b.js_raw) with envset(BOKEH_RESOURCES="cdn"): b = beb.bundle_for_objs_and_resources([], INLINE) assert any('cdn' in x for x in b.js_files) # this is a cheap test that a BokehJS file is NOT inline assert all(len(x) < 5000 for x in b.js_raw)
def load_notebook(inline=True, load_timeout=5000): from IPython.display import publish_display_data resources = INLINE if inline else CDN bundle = bundle_for_objs_and_resources(None, resources) configs, requirements, exports = require_components() bokeh_js = _autoload_js(bundle, configs, requirements, exports, load_timeout) publish_display_data({ 'application/javascript': bokeh_js, LOAD_MIME: bokeh_js, }) bokeh.io.notebook.curstate().output_notebook() # Publish comm manager JS = '\n'.join([PYVIZ_PROXY, _JupyterCommManager.js_manager, nb_mime_js]) publish_display_data(data={LOAD_MIME: JS, 'application/javascript': JS})
async def get(self, *args, **kwargs): session = await self.get_session() bundle = bundle_for_objs_and_resources(None, self.application.resources()) render_item = { "token": session.token, "use_for_title": True, "bundle": { "js_files": bundle.js_files, "js_raw": bundle.js_raw, "css_files": bundle.css_files, "css_raw": bundle.css_raw } } self.write(json.dumps(render_item))
def server_html_page_for_session(session, resources, title, template=BASE_TEMPLATE, template_variables=None): render_item = RenderItem( token=session.token, roots=session.document.roots, use_for_title=False, ) if template_variables is None: template_variables = {} bundle = bundle_for_objs_and_resources(None, resources) bundle = Bundle.from_bokeh(bundle) return html_page_for_render_items(bundle, {}, [render_item], title, template=template, template_variables=template_variables)
def test_with_Server_resources(self) -> None: from ext_package_no_main import AModel model = AModel() bundle = beb.bundle_for_objs_and_resources([model], "server") assert len(bundle.js_files) == 2 assert len(bundle.js_raw) == 1
def test_with_INLINE_resources(self) -> None: from ext_package_no_main import AModel model = AModel() bundle = beb.bundle_for_objs_and_resources([model], "inline") assert len(bundle.js_files) == 0 assert len(bundle.js_raw) == 3