facett-demo 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. facett_demo-0.2.0/PKG-INFO +91 -0
  2. facett_demo-0.2.0/README.md +61 -0
  3. facett_demo-0.2.0/facett_demo/__init__.py +14 -0
  4. facett_demo-0.2.0/facett_demo/_buildinfo.py +3 -0
  5. facett_demo-0.2.0/facett_demo/app.py +146 -0
  6. facett_demo-0.2.0/facett_demo/buildinfo.py +84 -0
  7. facett_demo-0.2.0/facett_demo/cli.py +104 -0
  8. facett_demo-0.2.0/facett_demo/client.py +339 -0
  9. facett_demo-0.2.0/facett_demo/demo_payloads.json +572 -0
  10. facett_demo-0.2.0/facett_demo/demo_payloads.py +55 -0
  11. facett_demo-0.2.0/facett_demo/errcodes.json +797 -0
  12. facett_demo-0.2.0/facett_demo/facet_host.py +63 -0
  13. facett_demo-0.2.0/facett_demo/panes/__init__.py +1 -0
  14. facett_demo-0.2.0/facett_demo/panes/errcode_pane.py +166 -0
  15. facett_demo-0.2.0/facett_demo/panes/gallery_pane.py +279 -0
  16. facett_demo-0.2.0/facett_demo/panes/graph_pane.py +87 -0
  17. facett_demo-0.2.0/facett_demo/panes/map_pane.py +101 -0
  18. facett_demo-0.2.0/facett_demo/panes/offline_pane.py +40 -0
  19. facett_demo-0.2.0/facett_demo/panes/population_pane.py +165 -0
  20. facett_demo-0.2.0/facett_demo/proto/__init__.py +21 -0
  21. facett_demo-0.2.0/facett_demo/proto/korp_pb2.py +264 -0
  22. facett_demo-0.2.0/facett_demo/proto/korp_pb2_grpc.py +2085 -0
  23. facett_demo-0.2.0/facett_demo/proto/saga.proto +61 -0
  24. facett_demo-0.2.0/facett_demo/proto/saga_pb2.py +50 -0
  25. facett_demo-0.2.0/facett_demo/proto/saga_pb2_grpc.py +187 -0
  26. facett_demo-0.2.0/facett_demo/saga.py +328 -0
  27. facett_demo-0.2.0/facett_demo/theme.py +23 -0
  28. facett_demo-0.2.0/facett_demo.egg-info/PKG-INFO +91 -0
  29. facett_demo-0.2.0/facett_demo.egg-info/SOURCES.txt +33 -0
  30. facett_demo-0.2.0/facett_demo.egg-info/dependency_links.txt +1 -0
  31. facett_demo-0.2.0/facett_demo.egg-info/entry_points.txt +2 -0
  32. facett_demo-0.2.0/facett_demo.egg-info/requires.txt +9 -0
  33. facett_demo-0.2.0/facett_demo.egg-info/top_level.txt +1 -0
  34. facett_demo-0.2.0/pyproject.toml +65 -0
  35. facett_demo-0.2.0/setup.cfg +4 -0
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: facett-demo
3
+ Version: 0.2.0
4
+ Summary: facett's components in a Streamlit app: every Rust component drawn by wasm on WebGPU, grouped like facett-demo, graphs generated in the wasm up to 100 000 nodes — no server needed; live korp data with the [korp] extra.
5
+ Author: ignalina
6
+ Maintainer: ignalina
7
+ License-Expression: MIT OR Apache-2.0
8
+ Project-URL: Homepage, https://ignalina.dk
9
+ Project-URL: Repository, https://codeberg.org/nordisk/facett
10
+ Project-URL: Live demo, https://nordisk.codeberg.page/facett/
11
+ Project-URL: Issues, https://codeberg.org/nordisk/facett/issues
12
+ Keywords: facett,streamlit,wasm,webgpu,demo,graph,map,korp
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Web Environment
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Intended Audience :: Science/Research
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Topic :: Scientific/Engineering :: Visualization
21
+ Requires-Python: >=3.10
22
+ Description-Content-Type: text/markdown
23
+ Requires-Dist: facett[streamlit]<0.3,>=0.2.0
24
+ Provides-Extra: korp
25
+ Requires-Dist: grpcio>=1.60; extra == "korp"
26
+ Requires-Dist: protobuf<8,>=5; extra == "korp"
27
+ Provides-Extra: dev
28
+ Requires-Dist: grpcio-tools>=1.60; extra == "dev"
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+
31
+ # facett-demo
32
+
33
+ **facett's components in a Streamlit app.** Every facett component — graphs, maps,
34
+ tables, charts, timelines, a docs viewer, a 3-D model viewer, a simulation view — is
35
+ the real Rust component compiled to WebAssembly and drawn on WebGPU, grouped like the
36
+ native facett demo's tabs (Grafer, Kartor, Tabeller & diagram, Bygg & jobb, App & UI).
37
+ The graph components carry the demo's size + generator: up to 100 000 nodes (the
38
+ universe to 1 000 000) generated *inside the wasm*, so no graph crosses from Python.
39
+
40
+ No server is needed. With the optional `[korp]` extra the app also shows LIVE data
41
+ from a korp-server over gRPC.
42
+
43
+ * The components on their own: [`facett`](https://pypi.org/project/facett/)
44
+ * Live demo of the native facett demo, in the browser: <https://nordisk.codeberg.page/facett/>
45
+ * Source: <https://codeberg.org/nordisk/facett> (this app is `py/`)
46
+
47
+ ## Install and run
48
+
49
+ ```bash
50
+ pip install facett-demo
51
+ facett-demo # http://127.0.0.1:8501
52
+ facett-demo run --server.port 8502 # any Streamlit option after `run`
53
+ facett-demo --version # facett-demo <version> (<git hash>)
54
+ facett-demo about # build banner + which tabs read which korp RPC
55
+ ```
56
+
57
+ `facett-demo` starts Streamlit in the same Python process (no `streamlit` executable
58
+ needed on `PATH`) and binds to **127.0.0.1** unless told otherwise — the demo is not
59
+ authenticated, so exposing it is an explicit choice (`--server.address`).
60
+
61
+ Open it in a browser with WebGPU in a secure context (`localhost` or https). Chrome
62
+ on Linux needs `--enable-unsafe-webgpu --enable-features=Vulkan`.
63
+
64
+ ## Live korp data (optional)
65
+
66
+ ```bash
67
+ pip install 'facett-demo[korp]' # + grpcio, protobuf
68
+ KORP_SERVER=host:50051 facett-demo
69
+ ```
70
+
71
+ | tab | component | korp-server RPC |
72
+ |---|---|---|
73
+ | 🗺 korp · Map | `osm2d` | `Assets` + `MapQuery` |
74
+ | 🕸 korp · Graph | `graphnav` | `Graph` |
75
+ | 📊 korp · Population | `table` + `stat-grid` | `IcebergTables` + `TablePreview` + `Population` |
76
+
77
+ Without the extra the app runs offline: the 🎨 Komponenter tab of every group needs no
78
+ server, and the korp tabs mount the same components on the gallery's generated/fixture
79
+ data under a banner that says so. With the extra installed and the server down, every
80
+ korp tab shows the server's own error instead of a blank pane.
81
+
82
+ ## How it is built
83
+
84
+ The `facett` wheel carries the wasm bundles; this package is pure Python (the app,
85
+ its payload table and the error-code catalog). Both wheels are built in a pinned
86
+ container with the network off and verified byte for byte against their own `RECORD`
87
+ before release; see the repository's `.nornir/pypi-publish.md`.
88
+
89
+ ## License
90
+
91
+ MIT OR Apache-2.0.
@@ -0,0 +1,61 @@
1
+ # facett-demo
2
+
3
+ **facett's components in a Streamlit app.** Every facett component — graphs, maps,
4
+ tables, charts, timelines, a docs viewer, a 3-D model viewer, a simulation view — is
5
+ the real Rust component compiled to WebAssembly and drawn on WebGPU, grouped like the
6
+ native facett demo's tabs (Grafer, Kartor, Tabeller & diagram, Bygg & jobb, App & UI).
7
+ The graph components carry the demo's size + generator: up to 100 000 nodes (the
8
+ universe to 1 000 000) generated *inside the wasm*, so no graph crosses from Python.
9
+
10
+ No server is needed. With the optional `[korp]` extra the app also shows LIVE data
11
+ from a korp-server over gRPC.
12
+
13
+ * The components on their own: [`facett`](https://pypi.org/project/facett/)
14
+ * Live demo of the native facett demo, in the browser: <https://nordisk.codeberg.page/facett/>
15
+ * Source: <https://codeberg.org/nordisk/facett> (this app is `py/`)
16
+
17
+ ## Install and run
18
+
19
+ ```bash
20
+ pip install facett-demo
21
+ facett-demo # http://127.0.0.1:8501
22
+ facett-demo run --server.port 8502 # any Streamlit option after `run`
23
+ facett-demo --version # facett-demo <version> (<git hash>)
24
+ facett-demo about # build banner + which tabs read which korp RPC
25
+ ```
26
+
27
+ `facett-demo` starts Streamlit in the same Python process (no `streamlit` executable
28
+ needed on `PATH`) and binds to **127.0.0.1** unless told otherwise — the demo is not
29
+ authenticated, so exposing it is an explicit choice (`--server.address`).
30
+
31
+ Open it in a browser with WebGPU in a secure context (`localhost` or https). Chrome
32
+ on Linux needs `--enable-unsafe-webgpu --enable-features=Vulkan`.
33
+
34
+ ## Live korp data (optional)
35
+
36
+ ```bash
37
+ pip install 'facett-demo[korp]' # + grpcio, protobuf
38
+ KORP_SERVER=host:50051 facett-demo
39
+ ```
40
+
41
+ | tab | component | korp-server RPC |
42
+ |---|---|---|
43
+ | 🗺 korp · Map | `osm2d` | `Assets` + `MapQuery` |
44
+ | 🕸 korp · Graph | `graphnav` | `Graph` |
45
+ | 📊 korp · Population | `table` + `stat-grid` | `IcebergTables` + `TablePreview` + `Population` |
46
+
47
+ Without the extra the app runs offline: the 🎨 Komponenter tab of every group needs no
48
+ server, and the korp tabs mount the same components on the gallery's generated/fixture
49
+ data under a banner that says so. With the extra installed and the server down, every
50
+ korp tab shows the server's own error instead of a blank pane.
51
+
52
+ ## How it is built
53
+
54
+ The `facett` wheel carries the wasm bundles; this package is pure Python (the app,
55
+ its payload table and the error-code catalog). Both wheels are built in a pinned
56
+ container with the network off and verified byte for byte against their own `RECORD`
57
+ before release; see the repository's `.nornir/pypi-publish.md`.
58
+
59
+ ## License
60
+
61
+ MIT OR Apache-2.0.
@@ -0,0 +1,14 @@
1
+ """facett-demo — facett's components in a Streamlit app (``pip install facett-demo``).
2
+
3
+ The Streamlit twin of the native ``facett-demo``: every facett component (Rust → wasm,
4
+ drawn on WebGPU) grouped like the demo's tabs, with the demo's size + generator for the
5
+ graph components — no server needed. With the optional ``[korp]`` extra it also shows
6
+ LIVE data from a korp-server (gRPC). Run it with the ``facett-demo`` command.
7
+
8
+ Until 0.2.0 this was the unpublished ``facett-demo-python`` (import
9
+ ``facett_demo_python``), run from a source checkout.
10
+ """
11
+
12
+ from .buildinfo import __version__, build_info, version_string
13
+
14
+ __all__ = ["__version__", "build_info", "version_string"]
@@ -0,0 +1,3 @@
1
+ """Baked build stamp — written by `cargo ops publish-pip` into the staged package. Do not edit."""
2
+ GIT_HASH = "340af30"
3
+ BUILD_TIME = "SOURCE_DATE_EPOCH=1788566400"
@@ -0,0 +1,146 @@
1
+ """facett-demo — Streamlit entrypoint.
2
+
3
+ Run with the installed command (Streamlit is started in-process)::
4
+
5
+ facett-demo # 127.0.0.1:8501
6
+ facett-demo run --server.port 8502
7
+
8
+ or ``streamlit run <site-packages>/facett_demo/app.py``.
9
+
10
+ Mirrors facett-demo's core surfaces (MAP / GRAPH / POPULATION), each driven by a
11
+ LIVE korp-server RPC. The sidebar shows this app's version+git-hash AND the
12
+ connected server's version+hash, so it is always obvious which build backs the
13
+ demo. Every pane shows an honest "server unreachable / empty" panel rather than a
14
+ blank false-green when the server cannot answer.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import os
20
+ from typing import Any
21
+
22
+ import streamlit as st
23
+
24
+ from facett_demo.buildinfo import build_info, version_string
25
+ from facett_demo.client import (
26
+ DEFAULT_TARGET,
27
+ KORP_EXTRA_HINT,
28
+ KorpClient,
29
+ KorpUnavailable,
30
+ korp_available,
31
+ )
32
+ from facett_demo.panes import (
33
+ gallery_pane,
34
+ map_pane,
35
+ graph_pane,
36
+ population_pane,
37
+ errcode_pane,
38
+ offline_pane,
39
+ )
40
+
41
+
42
+ def _sidebar() -> KorpClient:
43
+ st.sidebar.title("facett-demo")
44
+ st.sidebar.caption("Python/Streamlit companion to facett-demo")
45
+
46
+ bi = build_info()
47
+ st.sidebar.markdown("**App build**")
48
+ st.sidebar.code(f"{bi['version']} ({bi['git_hash']})\nsource: {bi['source']}", language=None)
49
+
50
+ target = st.sidebar.text_input("korp-server", value=DEFAULT_TARGET, key="server_target")
51
+ client = KorpClient(target=target)
52
+
53
+ st.sidebar.markdown("**Server**")
54
+ if not korp_available():
55
+ # The [korp] extra is optional: say so instead of probing a wire that is not here.
56
+ st.sidebar.info(f"korp wire not installed — offline mode\n\n`{KORP_EXTRA_HINT}`")
57
+ else:
58
+ try:
59
+ h = client.health()
60
+ st.sidebar.success(f"connected · {h.status}")
61
+ st.sidebar.code(f"korp {h.version}\nuptime {h.uptime_seconds}s", language=None)
62
+ except KorpUnavailable as e:
63
+ st.sidebar.error("server unreachable")
64
+ st.sidebar.code(str(e), language=None)
65
+
66
+ # Dev mode: every canvas shows its navgraph numbers (1, 1.1, 1.1.~3 …). The wasm
67
+ # draws them; Ctrl+Shift+G in a canvas cycles the overlay, Ctrl+G <n> Enter focuses.
68
+ # Starts ON when the app runs with FACETT_DEVID=1 (the same switch as a release
69
+ # facett binary's dev-id chips).
70
+ dev_default = os.environ.get("FACETT_DEVID", "").strip().lower() in ("1", "true", "on", "yes")
71
+ st.sidebar.toggle("dev mode · navgraph numbers", value=dev_default, key="dev_mode")
72
+ st.sidebar.caption("🎨 Komponenter (every group) → the shipped wasm (no RPC, no server)")
73
+ st.sidebar.caption("korp tabs → live RPCs:")
74
+ st.sidebar.caption("🗺 Map → Assets + MapQuery")
75
+ st.sidebar.caption("🕸 Graph → Graph")
76
+ st.sidebar.caption("📊 Population → IcebergTables + TablePreview + Population")
77
+ st.sidebar.caption("🩷 Errors → the facett error-code catalog (static, no RPC)")
78
+ return client
79
+
80
+
81
+ #: The live korp panes, each filed under the facett-demo tab group its surface belongs
82
+ #: to (`gallery_pane.GROUPS`): the map under Kartor, the graph navigator under Grafer,
83
+ #: the Iceberg browser + population diagrams under Tabeller & diagram, the error-code
84
+ #: catalog under App & UI (where the demo keeps `Errors`).
85
+ #:
86
+ #: The third field is what the tab mounts WITHOUT the korp wire (the optional
87
+ #: `[korp]` extra): the same components on the gallery's generated/fixture data,
88
+ #: under a banner that says so (`offline_pane`). `None` = the pane needs no korp.
89
+ _LIVE_PANES: dict[str, list[tuple[str, Any, list[str] | None]]] = {
90
+ "graph": [("\U0001F578 korp · Graph", graph_pane.render, [graph_pane.COMPONENT])],
91
+ "map": [("\U0001F5FA korp · Map", map_pane.render, [map_pane.COMPONENT])],
92
+ "data": [(
93
+ "\U0001F4CA korp · Population",
94
+ population_pane.render,
95
+ [population_pane.STAT_COMPONENT, population_pane.TABLE_COMPONENT],
96
+ )],
97
+ "ui": [("\U0001FA77 Errors", errcode_pane.render, None)],
98
+ }
99
+
100
+ #: The sub-tab every group opens on: the gallery's wasm components for that group.
101
+ COMPONENTS_TAB = "\U0001F3A8 Komponenter"
102
+
103
+
104
+ def main() -> None:
105
+ st.set_page_config(page_title="facett-demo", page_icon="🧭", layout="wide")
106
+ st.title("🧭 facett-demo")
107
+ st.caption(
108
+ "Grouped like facett-demo's tabs (Grafer, Kartor, …). In each group, "
109
+ "**Komponenter** is facett-demo itself: every wrapped component, every pixel drawn "
110
+ "by the Rust wasm on WebGPU, no server needed — the graph components with the "
111
+ "demo's size + generator (100 → 100k, the universe to 1M, generated in the wasm). "
112
+ "The korp tabs beside it mirror facett-demo's live surfaces from the korp-server "
113
+ "gRPC control plane. No mocks, and no JavaScript renderer anywhere."
114
+ )
115
+
116
+ client = _sidebar()
117
+
118
+ # The GALLERY leads every group, and deliberately so. It is the facett-demo showcase
119
+ # and it needs NO korp-server, no database and no network: a demo whose first tab
120
+ # is empty because a backend is down is a demo nobody can show. The live-RPC panes
121
+ # follow it inside their group.
122
+ mode = gallery_pane.render_header()
123
+ groups = gallery_pane.top_groups()
124
+ for tab, (key, _label) in zip(st.tabs([label for _, label in groups]), groups):
125
+ with tab:
126
+ live = _LIVE_PANES.get(key, [])
127
+ if not live:
128
+ gallery_pane.render_group(key, mode)
129
+ continue
130
+ subs = st.tabs([COMPONENTS_TAB] + [name for name, _, _ in live])
131
+ with subs[0]:
132
+ gallery_pane.render_group(key, mode)
133
+ for sub, (name, pane, offline) in zip(subs[1:], live):
134
+ with sub:
135
+ if offline is not None and not korp_available():
136
+ offline_pane.render(name, offline, key=key)
137
+ else:
138
+ pane(client)
139
+
140
+ st.divider()
141
+ st.caption(f"{version_string()} · server target `{os.environ.get('KORP_SERVER', DEFAULT_TARGET)}`")
142
+
143
+
144
+ # Streamlit (and AppTest) execute this module top-to-bottom on every rerun, so
145
+ # main() is called unconditionally — no __main__ guard (there is no double run).
146
+ main()
@@ -0,0 +1,84 @@
1
+ """Version + git-hash stamp (build-version-githash LAW).
2
+
3
+ Every binary/app in the suite embeds its version + git-hash, SHOWS it in the app
4
+ (here: the sidebar) and answers a ``--version``/about query. We resolve the hash
5
+ in three tiers, most-authoritative first:
6
+
7
+ 1. a baked ``_buildinfo.py`` (written by ``scripts/stamp.py`` at build/commit time);
8
+ 2. a live ``git rev-parse`` of the checkout the package sits in (dev runs);
9
+ 3. the literal ``"unknown"`` — an HONEST fallback, never a fake hash.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import subprocess
15
+ from importlib import metadata as _metadata
16
+ from pathlib import Path
17
+
18
+ #: The package version, read from the INSTALLED distribution's own metadata — the
19
+ #: ONE writer is py/pyproject.toml (held to facett-build-thing's PYPI_VERSION by
20
+ #: xtask/tests/python_versions_track_the_workspace.rs). A source checkout that was
21
+ #: never installed answers `0+unknown` rather than a plausible-looking stale literal
22
+ #: (the components package learned that the hard way: 0.1.15 inside a 0.1.19 wheel).
23
+ try:
24
+ __version__ = _metadata.version("facett-demo")
25
+ except _metadata.PackageNotFoundError: # pragma: no cover - source checkout only
26
+ __version__ = "0+unknown"
27
+
28
+ _UNKNOWN = "unknown"
29
+
30
+
31
+ def _baked() -> tuple[str, str] | None:
32
+ """Return (git_hash, build_time) baked at build time, or None."""
33
+ try:
34
+ from . import _buildinfo # type: ignore
35
+
36
+ return (
37
+ getattr(_buildinfo, "GIT_HASH", _UNKNOWN),
38
+ getattr(_buildinfo, "BUILD_TIME", _UNKNOWN),
39
+ )
40
+ except Exception:
41
+ return None
42
+
43
+
44
+ def _live_git_hash() -> str:
45
+ """Best-effort short hash of the checkout this file lives in."""
46
+ try:
47
+ out = subprocess.run(
48
+ ["git", "rev-parse", "--short", "HEAD"],
49
+ cwd=str(Path(__file__).resolve().parent),
50
+ capture_output=True,
51
+ text=True,
52
+ timeout=3,
53
+ )
54
+ if out.returncode == 0:
55
+ h = out.stdout.strip()
56
+ if h:
57
+ return h
58
+ except Exception:
59
+ pass
60
+ return _UNKNOWN
61
+
62
+
63
+ def build_info() -> dict[str, str]:
64
+ """Resolve {version, git_hash, build_time, source} for display + --version."""
65
+ baked = _baked()
66
+ if baked is not None and baked[0] != _UNKNOWN:
67
+ git_hash, build_time = baked
68
+ source = "baked"
69
+ else:
70
+ git_hash = _live_git_hash()
71
+ build_time = _UNKNOWN
72
+ source = "live-git" if git_hash != _UNKNOWN else "none"
73
+ return {
74
+ "version": __version__,
75
+ "git_hash": git_hash,
76
+ "build_time": build_time,
77
+ "source": source,
78
+ }
79
+
80
+
81
+ def version_string() -> str:
82
+ """A one-line version banner, mirroring facett's ``<ver> (<hash>)`` form."""
83
+ bi = build_info()
84
+ return f"facett-demo {bi['version']} ({bi['git_hash']})"
@@ -0,0 +1,104 @@
1
+ """`facett-demo` — start the demo, or say what it is (build-version-githash LAW).
2
+
3
+ facett-demo # the app on http://127.0.0.1:8501
4
+ facett-demo run [streamlit options] # e.g. run --server.port 8502
5
+ facett-demo --version | about
6
+
7
+ Streamlit is started IN-PROCESS through its own Python entry point
8
+ (``streamlit.web.cli``) — the same call the ``streamlit`` console script makes — rather
9
+ than by spawning a ``streamlit`` executable, so the demo needs nothing on ``PATH`` and
10
+ runs under exactly the interpreter it was installed into.
11
+
12
+ The default bind address is LOOPBACK (``127.0.0.1``), on purpose: nothing about a demo
13
+ is authenticated, and a 0.0.0.0 bind on a workstation once published it to the
14
+ internet. Pass ``--server.address`` to choose otherwise.
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ import argparse
20
+ import sys
21
+ from pathlib import Path
22
+
23
+ from .buildinfo import build_info, version_string
24
+
25
+ #: The app script Streamlit runs — inside the INSTALLED package.
26
+ APP = Path(__file__).resolve().parent / "app.py"
27
+
28
+ #: Options the demo sets unless the caller passes its own.
29
+ DEFAULTS: dict[str, str] = {
30
+ "--server.address": "127.0.0.1",
31
+ "--server.port": "8501",
32
+ "--server.headless": "true",
33
+ "--browser.gatherUsageStats": "false",
34
+ }
35
+
36
+
37
+ def _about() -> str:
38
+ bi = build_info()
39
+ from .client import DEFAULT_TARGET, KORP_EXTRA_HINT, korp_available
40
+
41
+ korp = "installed" if korp_available() else f"NOT installed — offline mode ({KORP_EXTRA_HINT})"
42
+ lines = [
43
+ version_string(),
44
+ f" version : {bi['version']}",
45
+ f" git-hash : {bi['git_hash']}",
46
+ f" build-time : {bi['build_time']}",
47
+ f" hash-source: {bi['source']}",
48
+ f" korp wire : {korp}",
49
+ f" korp-server: {DEFAULT_TARGET} (override with $KORP_SERVER)",
50
+ " panes : Komponenter (every wasm component, no server) · Map(Assets+MapQuery) · "
51
+ "Graph(Graph) · Population(IcebergTables+TablePreview+Population) · Errors",
52
+ ]
53
+ return "\n".join(lines)
54
+
55
+
56
+ def streamlit_argv(extra: list[str]) -> list[str]:
57
+ """The ``streamlit run`` arguments: the app, the caller's options, then any of
58
+ :data:`DEFAULTS` the caller did not set (``--opt value`` or ``--opt=value``)."""
59
+ given = {a.split("=", 1)[0] for a in extra if a.startswith("--")}
60
+ argv = ["run", str(APP), *extra]
61
+ for opt, value in DEFAULTS.items():
62
+ if opt not in given:
63
+ argv += [opt, value]
64
+ return argv
65
+
66
+
67
+ def run(extra: list[str]) -> int:
68
+ """Run the app in THIS process, through Streamlit's own CLI entry point."""
69
+ try:
70
+ from streamlit.web import cli as stcli
71
+ except ImportError as e: # facett[streamlit] is a hard dependency; say so if it is gone
72
+ print(f"facett-demo needs Streamlit (pip install 'facett[streamlit]'): {e}", file=sys.stderr)
73
+ return 2
74
+ try:
75
+ stcli.main(args=streamlit_argv(extra), prog_name="facett-demo", standalone_mode=True)
76
+ except SystemExit as e: # click exits; turn it into our return code
77
+ return int(e.code or 0) if not isinstance(e.code, str) else 1
78
+ return 0
79
+
80
+
81
+ def main(argv: list[str] | None = None) -> int:
82
+ argv = sys.argv[1:] if argv is None else argv
83
+ # `run` passes everything after it to Streamlit untouched (its own --server.* flags).
84
+ if argv[:1] == ["run"]:
85
+ return run(argv[1:])
86
+
87
+ p = argparse.ArgumentParser(prog="facett-demo", description="facett's components in a Streamlit app")
88
+ p.add_argument("--version", action="store_true", help="print version + git-hash and exit")
89
+ sub = p.add_subparsers(dest="cmd")
90
+ sub.add_parser("about", help="print the full build/about banner")
91
+ sub.add_parser("run", help="start the app (default); Streamlit options follow")
92
+ args = p.parse_args(argv)
93
+
94
+ if args.version:
95
+ print(version_string())
96
+ return 0
97
+ if args.cmd == "about":
98
+ print(_about())
99
+ return 0
100
+ return run([])
101
+
102
+
103
+ if __name__ == "__main__":
104
+ sys.exit(main())