facett 0.2.0__py3-none-any.whl

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.
@@ -0,0 +1,40 @@
1
+ """facet_wrapped_web — the pre-0.2.0 import name of :mod:`facett`, kept for ONE release.
2
+
3
+ The package was published as ``facet-wrapped-web`` (0.1.x) and is ``facett`` from
4
+ 0.2.0. This alias ships inside the ``facett`` wheel so existing ``import
5
+ facet_wrapped_web`` lines keep working while they are changed to ``import facett``; it
6
+ is removed in 0.3.0. It re-exports the SAME functions (not copies), so the two names
7
+ cannot disagree about where the assets are.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import warnings
13
+
14
+ from facett import ( # noqa: F401 - re-exported
15
+ __version__,
16
+ assets_dir,
17
+ build_info,
18
+ bundles,
19
+ data_driven,
20
+ is_data_driven,
21
+ manifest,
22
+ wasm_path,
23
+ )
24
+
25
+ __all__ = [
26
+ "__version__",
27
+ "assets_dir",
28
+ "wasm_path",
29
+ "bundles",
30
+ "manifest",
31
+ "data_driven",
32
+ "is_data_driven",
33
+ "build_info",
34
+ ]
35
+
36
+ warnings.warn(
37
+ "facet_wrapped_web is now `facett` (pip install facett); this alias is removed in 0.3.0",
38
+ DeprecationWarning,
39
+ stacklevel=2,
40
+ )
facett/__init__.py ADDED
@@ -0,0 +1,148 @@
1
+ """facett — the compiled facett components (Rust → wasm) and a host-agnostic loader page.
2
+
3
+ This module is **delivery only**. It contains no rendering code and imports no UI
4
+ framework: it carries the `facet-wrapped` wasm bundles (core, docs, model3d, sim), their
5
+ wasm-bindgen JS, each bundle's component manifest, the routing table, and a
6
+ host-agnostic `index.html` that mounts a chosen component onto a WebGPU canvas. A host
7
+ application points its own embedding mechanism at :func:`assets_dir` and drives the
8
+ loader with `component` / `data` parameters.
9
+
10
+ Streamlit support is the OPTIONAL extra, in its own module, so that plain
11
+ ``import facett`` never needs Streamlit::
12
+
13
+ pip install facett # the components + loader; no dependencies
14
+ pip install 'facett[streamlit]' # + facett.streamlit.facett_component(...)
15
+
16
+ import facett
17
+ facett.assets_dir() # serve this directory, load index.html
18
+ [c["name"] for c in facett.manifest()] # every component of every bundle
19
+
20
+ Until 0.2.0 this package was published as ``facet-wrapped-web`` and imported as
21
+ ``facet_wrapped_web``; that import name still works for one release (a thin alias
22
+ module in the same wheel) and warns.
23
+ """
24
+
25
+ from __future__ import annotations
26
+
27
+ import json
28
+ from importlib import metadata as _metadata
29
+ from pathlib import Path
30
+ from typing import Any
31
+
32
+ __all__ = [
33
+ "__version__",
34
+ "assets_dir",
35
+ "wasm_path",
36
+ "bundles",
37
+ "manifest",
38
+ "data_driven",
39
+ "is_data_driven",
40
+ "build_info",
41
+ ]
42
+
43
+ #: Package version, read from the INSTALLED distribution's own metadata.
44
+ #:
45
+ #: This used to be a literal, and on 2026-09-05 it was `"0.1.15"` inside a wheel
46
+ #: whose metadata said `0.1.19`. `build_info()` returns this string and
47
+ #: `tests/robot_installed.py` records it into the saga tape, so the durable record
48
+ #: of every drive was stamped with a version the artifact did not have — and
49
+ #: nothing could catch it from inside python, because the number agreed with
50
+ #: itself.
51
+ #:
52
+ #: A fourth copy held in place by a test is still a fourth copy. `pyproject.toml`
53
+ #: is the ONE writer of this version; setuptools writes it into the wheel's
54
+ #: METADATA, and this reads it back from there. There is now no second number to
55
+ #: drift.
56
+ #:
57
+ #: Running from a source checkout (not installed) has no distribution metadata to
58
+ #: read. That answers `0+unknown` rather than a plausible-looking number: a
59
+ #: version that is obviously absent is safe, and a stale one that looks real is
60
+ #: exactly what this replaced.
61
+ try:
62
+ __version__ = _metadata.version("facett")
63
+ except _metadata.PackageNotFoundError: # pragma: no cover - source checkout only
64
+ __version__ = "0+unknown"
65
+
66
+ _ASSETS = Path(__file__).parent / "assets"
67
+
68
+
69
+ def assets_dir() -> Path:
70
+ """Directory holding `index.html`, the wasm, its JS glue and `manifest.json`.
71
+
72
+ A host serves this directory (or points an iframe/component at it) and loads
73
+ `index.html`.
74
+ """
75
+ return _ASSETS
76
+
77
+
78
+ def wasm_path() -> Path:
79
+ """Path to the compiled component wasm."""
80
+ return _ASSETS / "facet_wrapped_bg.wasm"
81
+
82
+
83
+ def bundles() -> dict[str, Any]:
84
+ """The routing table beside the loader (`assets/bundles.json`), as emitted by
85
+ facett-build-thing (`BUNDLE_GROUPS`): `{default, groups: [{name, dir, manifest, …}]}`.
86
+
87
+ Empty (`{}`) when the file is absent, which only a source checkout without a
88
+ built bundle can be — a wheel without it is refused by `facett_ops::pip::verify_wheel`.
89
+ """
90
+ rt = _ASSETS / "bundles.json"
91
+ if rt.exists():
92
+ return json.loads(rt.read_text())
93
+ return {}
94
+
95
+
96
+ def manifest() -> list[dict[str, Any]]:
97
+ """The component manifest of EVERY shipped bundle:
98
+ `[{name, description, group, title, data_driven, bundle}]`.
99
+
100
+ One list, read off each bundle group's own `manifest.json` in the routing table's
101
+ order (core first). `bundle` names the group whose wasm holds the component, so a
102
+ host can tell `docview` (docs bundle) from `table` (core) — the loader routes by
103
+ the same table, so a host mounting any name here gets the right bundle.
104
+
105
+ This used to read `assets/manifest.json` alone — the CORE bundle's — so the docs
106
+ and model3d bundles shipped inside the wheel and no host could list them: the
107
+ Streamlit gallery never mounted docview, manual or model3d (lane S, dwarf,
108
+ 2026-09-29).
109
+ """
110
+ rt = bundles()
111
+ groups = rt.get("groups") or [{"name": "core", "manifest": "manifest.json"}]
112
+ out: list[dict[str, Any]] = []
113
+ for g in groups:
114
+ mf = _ASSETS / g.get("manifest", "manifest.json")
115
+ if not mf.exists():
116
+ continue
117
+ for c in json.loads(mf.read_text()):
118
+ out.append({**c, "bundle": g.get("name", "core")})
119
+ return out
120
+
121
+
122
+ def data_driven() -> list[str]:
123
+ """Names of components that render caller-supplied data."""
124
+ return [c["name"] for c in manifest() if c.get("data_driven")]
125
+
126
+
127
+ def is_data_driven(name: str) -> bool:
128
+ """Whether `name` accepts a data payload (False if unknown or not shipped)."""
129
+ return name in data_driven()
130
+
131
+
132
+ def build_info() -> dict[str, Any]:
133
+ """Identity of the SHIPPED artifact — version, wasm size, component counts.
134
+
135
+ Tests assert on this so a stale or truncated wheel is caught rather than silently
136
+ exercised: a wheel can ship a missing or outdated wasm while every source-level
137
+ test still passes.
138
+ """
139
+ w = wasm_path()
140
+ m = manifest()
141
+ return {
142
+ "version": __version__,
143
+ "wasm_present": w.exists(),
144
+ "wasm_bytes": w.stat().st_size if w.exists() else 0,
145
+ "components": len(m),
146
+ "data_driven": sum(1 for c in m if c.get("data_driven")),
147
+ "assets_dir": str(_ASSETS),
148
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "_": "EMITTED by facett-build-thing (BUNDLE_GROUPS) — do not edit; re-run `cargo run -p facett-build-thing -- emit`",
3
+ "schema": 2,
4
+ "default": "core",
5
+ "groups": [
6
+ {"name": "core", "dir": "", "wasm": "facet_wrapped_bg.wasm", "js": "facet_wrapped.js", "manifest": "manifest.json", "features": [], "entries": []},
7
+ {"name": "docs", "dir": "docs", "wasm": "docs/facet_wrapped_group_bg.wasm", "js": "docs/facet_wrapped_group.js", "manifest": "docs/manifest.json", "features": ["docs"], "entries": ["docview", "manual"]},
8
+ {"name": "model3d", "dir": "model3d", "wasm": "model3d/facet_wrapped_group_bg.wasm", "js": "model3d/facet_wrapped_group.js", "manifest": "model3d/manifest.json", "features": ["model3d"], "entries": ["model3d"]},
9
+ {"name": "sim", "dir": "sim", "wasm": "sim/facet_wrapped_group_bg.wasm", "js": "sim/facet_wrapped_group.js", "manifest": "sim/manifest.json", "features": ["sim"], "entries": ["simview"]}
10
+ ]
11
+ }