-
Notifications
You must be signed in to change notification settings - Fork 0
Use runtime workspace resolver in Marimo #1
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
Changes from 8 commits
38a286a
4929c60
b0482c3
c1b6ef1
155f587
9cee4c7
57cb511
847663f
5011915
2183373
ac68bbc
dd4e290
5509eb6
0e1113d
367a9ff
77feaab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import marimo as mo | ||
| from hotdata_runtime.client import HotdataClient | ||
| from hotdata_runtime.env import ( | ||
| from hotdata_runtime import ( | ||
| HotdataClient, | ||
| default_api_key, | ||
| default_host, | ||
| default_session_id, | ||
| explicit_workspace_id, | ||
| list_workspaces, | ||
| resolve_workspace_selection, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -25,25 +24,19 @@ def __init__( | |
| self._api_key = api_key | ||
| self._host = host or default_host() | ||
| self._session_id = session_id | ||
| self._explicit = explicit_workspace_id() | ||
|
|
||
| workspaces = list_workspaces(api_key, self._host, session_id) | ||
| if not workspaces: | ||
| raise RuntimeError("No Hotdata workspaces found for this API key.") | ||
|
|
||
| selection = resolve_workspace_selection(api_key, self._host, session_id) | ||
| self._explicit = selection.source == "explicit_env" | ||
| if self._explicit: | ||
| self._pick = None | ||
| self._workspace_id = self._explicit | ||
| self._workspace_id = selection.workspace_id | ||
| return | ||
|
|
||
| workspaces = selection.workspaces | ||
| if len(workspaces) == 1: | ||
| self._pick = None | ||
| self._workspace_id = workspaces[0].public_id | ||
| return | ||
|
|
||
| active = [w for w in workspaces if w.active] | ||
| chosen = active[0] if active else workspaces[0] | ||
|
|
||
| labels: list[tuple[str, str]] = [] | ||
| seen: set[str] = set() | ||
| for w in workspaces: | ||
|
|
@@ -52,10 +45,10 @@ def __init__( | |
| seen.add(base) | ||
| labels.append((label_text, w.public_id)) | ||
|
|
||
| labels.sort(key=lambda t: 0 if t[1] == chosen.public_id else 1) | ||
| labels.sort(key=lambda t: 0 if t[1] == selection.workspace_id else 1) | ||
| options = {k: v for k, v in labels} | ||
| self._pick = mo.ui.dropdown(options=options, label=label, full_width=True) | ||
| self._workspace_id = chosen.public_id | ||
| self._workspace_id = selection.workspace_id | ||
|
Comment on lines
34
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: the prior code raised |
||
|
|
||
| @property | ||
| def workspace_id(self) -> str: | ||
|
|
@@ -84,7 +77,7 @@ def ui(self): | |
| def workspace_selector_from_env(*, label: str = "Workspace") -> WorkspaceSelector: | ||
| api_key = default_api_key() | ||
| if not api_key: | ||
| raise RuntimeError("HOTDATA_API_KEY or HOTDATA_TOKEN must be set.") | ||
| raise RuntimeError("HOTDATA_API_KEY must be set.") | ||
| host = default_host() | ||
| session = default_session_id() | ||
| return WorkspaceSelector( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| REPO_ROOT = Path(__file__).resolve().parents[1] | ||
| SOURCE_ROOT = REPO_ROOT / "hotdata_marimo" | ||
|
|
||
|
|
||
| def test_source_uses_hotdata_runtime_root_imports() -> None: | ||
| violations: list[str] = [] | ||
| pattern = re.compile( | ||
| r"(?m)^\s*(?:from\s+hotdata_runtime\.(client|env|result|health)\s+import" | ||
| r"|import\s+hotdata_runtime\.(client|env|result|health)(?:\s|$|,|as))" | ||
| ) | ||
|
|
||
| for path in SOURCE_ROOT.rglob("*.py"): | ||
| text = path.read_text(encoding="utf-8") | ||
| if pattern.search(text): | ||
| violations.append(str(path.relative_to(REPO_ROOT))) | ||
|
|
||
| assert not violations, ( | ||
| "Use `from hotdata_runtime import ...` in package source; " | ||
| f"found submodule imports in: {', '.join(violations)}" | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| from hotdata_marimo.display import _option_map_with_unique_labels | ||
| from hotdata_marimo.table_browser import _connection_options | ||
|
|
||
|
|
||
| def test_option_map_with_unique_labels_keeps_all_values(): | ||
| options = _option_map_with_unique_labels( | ||
| [("dup", "a"), ("dup", "b"), ("dup", "c")] | ||
| ) | ||
| assert options == { | ||
| "dup": "a", | ||
| "dup (2)": "b", | ||
| "dup (3)": "c", | ||
| } | ||
|
|
||
|
|
||
| def test_connection_options_disambiguates_duplicate_names(): | ||
| conns = [ | ||
| SimpleNamespace(name="Warehouse", id="conn_1"), | ||
| SimpleNamespace(name="Warehouse", id="conn_2"), | ||
| SimpleNamespace(name="Analytics", id="conn_3"), | ||
| ] | ||
| options = _connection_options(conns) | ||
| assert options == { | ||
| "Warehouse": "conn_1", | ||
| "Warehouse (conn_2)": "conn_2", | ||
| "Analytics": "conn_3", | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.