Skip to content

Commit

Permalink
fix: Added enterprise checks for case where object name is a string #36
Browse files Browse the repository at this point in the history
Fixes #35

Added checks for enterprise info in case where object name is a string

Ran the following code and verified the chart appeared:

from deephaven_ipywidgets import DeephavenWidget

connection_info = "connection"
session_mgr: SessionManager = SessionManager(connection_info)
session_mgr.password("username","password")
session = session_mgr.connect_to_new_worker(name=None, heap_size_gb=1.0)

session.run_script("""
from deephaven import empty_table
from deephaven.plot.figure import Figure
t = empty_table(100).update(["X=i", "Y=i*i"])
f = Figure().plot_xy(series_name="X vs Y", t=t, x="X", y="Y").show()
""")

display(DeephavenWidget("f", session=session))
  • Loading branch information
jnumainville authored Feb 28, 2024
1 parent 8ffb289 commit 08c621f
Showing 1 changed file with 44 additions and 22 deletions.
66 changes: 44 additions & 22 deletions deephaven_ipywidgets/deephaven.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from __future__ import annotations

import __main__
from typing import Any

from ipywidgets import DOMWidget
from traitlets import Unicode, Integer, Bytes, Bool
from deephaven_server import Server
Expand All @@ -19,7 +21,6 @@
import base64
import atexit


TABLE_TYPES = {"deephaven.table.Table", "pandas.core.frame.DataFrame", "pydeephaven.table.Table"}
FIGURE_TYPES = {"deephaven.plot.figure.Figure"}

Expand Down Expand Up @@ -52,6 +53,44 @@ def _cleanup(widget: DeephavenWidget):
widget.set_trait("kernel_active", False)


def _check_session(session: Any, params: dict):
"""
Check the session for a session manager and set the parameters for the widget
Args:
session: The session to check
params: The parameters to set
Returns:
str, str: The server URL and token to use
"""

token = ""

port = session.port
server_url = f"http://{session.host}:{port}/"

if hasattr(session, "_extra_headers") and b"envoy-prefix" in session._extra_headers:
params["envoyPrefix"] = session._extra_headers[b"envoy-prefix"].decode(
"ascii"
)

if hasattr(session, "session_manager"):
params["authProvider"] = "parent"
# We have a DnD session, and we can get the authentication and connection details from the session manager
token = base64.b64encode(
session.session_manager.auth_client.get_token(
"RemoteQueryProcessor"
).SerializeToString()
).decode("us-ascii")
server_url = (
session.pqinfo().state.connectionDetails.staticUrl
)

return server_url, token


class DeephavenWidget(DOMWidget):
"""A wrapper for viewing DeephavenWidgets in IPython"""

Expand Down Expand Up @@ -96,30 +135,13 @@ def __init__(self, deephaven_object, height=600, width=0, session=None):
raise ValueError(
"session must be specified when using a remote pydeephaven object by name"
)
port = session.port
server_url = f"http://{session.host}:{port}/"

server_url, token = _check_session(session, params)

elif _str_object_type(deephaven_object) == "pydeephaven.table.Table":
session = deephaven_object.session

if b"envoy-prefix" in session._extra_headers:
params["envoyPrefix"] = session._extra_headers[b"envoy-prefix"].decode(
"ascii"
)

port = deephaven_object.session.port
server_url = f"http://{deephaven_object.session.host}:{port}/"

if hasattr(session, "session_manager"):
params["authProvider"] = "parent"
# We have a DnD session, and we can get the authentication and connection details from the session manager
token = base64.b64encode(
session.session_manager.auth_client.get_token(
"RemoteQueryProcessor"
).SerializeToString()
).decode("us-ascii")
server_url = (
deephaven_object.session.pqinfo().state.connectionDetails.staticUrl
)
server_url, token = _check_session(session, params)

session.bind_table(object_id, deephaven_object)
else:
Expand Down

0 comments on commit 08c621f

Please sign in to comment.