b3os 0.2.2__tar.gz → 0.2.3__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 (60) hide show
  1. {b3os-0.2.2 → b3os-0.2.3}/PKG-INFO +9 -2
  2. {b3os-0.2.2 → b3os-0.2.3}/README.md +8 -1
  3. {b3os-0.2.2 → b3os-0.2.3}/pyproject.toml +1 -1
  4. b3os-0.2.3/scripts/import-smoke.sh +30 -0
  5. b3os-0.2.3/scripts/import_smoke.py +225 -0
  6. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/async_namespaces.py +962 -18
  7. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/clients.py +10 -0
  8. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/errors.py +90 -0
  9. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/ids.py +8 -1
  10. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/namespaces.py +958 -17
  11. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/ops.py +43 -0
  12. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/types.py +1504 -30
  13. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_pty.py +9 -6
  14. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_util.py +1 -1
  15. {b3os-0.2.2 → b3os-0.2.3}/tests/test_prism.py +2 -3
  16. {b3os-0.2.2 → b3os-0.2.3}/uv.lock +1 -1
  17. {b3os-0.2.2 → b3os-0.2.3}/.gitignore +0 -0
  18. {b3os-0.2.2 → b3os-0.2.3}/LICENSE +0 -0
  19. {b3os-0.2.2 → b3os-0.2.3}/biome.json +0 -0
  20. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/__init__.py +0 -0
  21. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_async.py +0 -0
  22. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_base.py +0 -0
  23. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_client.py +0 -0
  24. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_errors.py +0 -0
  25. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_generated/__init__.py +0 -0
  26. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_handle.py +0 -0
  27. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_helpers.py +0 -0
  28. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_helpers_async.py +0 -0
  29. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_login.py +0 -0
  30. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_ops.py +0 -0
  31. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_options.py +0 -0
  32. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_response.py +0 -0
  33. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_sse.py +0 -0
  34. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_sync.py +0 -0
  35. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_timing.py +0 -0
  36. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_traces.py +0 -0
  37. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/_webhooks.py +0 -0
  38. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/helpers/__init__.py +0 -0
  39. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/helpers/render.py +0 -0
  40. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/helpers/render_async.py +0 -0
  41. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/helpers/sandboxes.py +0 -0
  42. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/helpers/sandboxes_async.py +0 -0
  43. {b3os-0.2.2 → b3os-0.2.3}/src/b3os/py.typed +0 -0
  44. {b3os-0.2.2 → b3os-0.2.3}/tests/conftest.py +0 -0
  45. {b3os-0.2.2 → b3os-0.2.3}/tests/server.py +0 -0
  46. {b3os-0.2.2 → b3os-0.2.3}/tests/test_client.py +0 -0
  47. {b3os-0.2.2 → b3os-0.2.3}/tests/test_handle.py +0 -0
  48. {b3os-0.2.2 → b3os-0.2.3}/tests/test_helpers.py +0 -0
  49. {b3os-0.2.2 → b3os-0.2.3}/tests/test_live.py +0 -0
  50. {b3os-0.2.2 → b3os-0.2.3}/tests/test_live_products.py +0 -0
  51. {b3os-0.2.2 → b3os-0.2.3}/tests/test_login.py +0 -0
  52. {b3os-0.2.2 → b3os-0.2.3}/tests/test_no_key.py +0 -0
  53. {b3os-0.2.2 → b3os-0.2.3}/tests/test_parity.py +0 -0
  54. {b3os-0.2.2 → b3os-0.2.3}/tests/test_query.py +0 -0
  55. {b3os-0.2.2 → b3os-0.2.3}/tests/test_sandbox_handle.py +0 -0
  56. {b3os-0.2.2 → b3os-0.2.3}/tests/test_sandboxes_create.py +0 -0
  57. {b3os-0.2.2 → b3os-0.2.3}/tests/test_speech_stream.py +0 -0
  58. {b3os-0.2.2 → b3os-0.2.3}/tests/test_turns.py +0 -0
  59. {b3os-0.2.2 → b3os-0.2.3}/tests/test_typing.py +0 -0
  60. {b3os-0.2.2 → b3os-0.2.3}/tests/typing_check.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: b3os
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Python SDK for B3OS beta: vision (web pages and browsers), render, infer, sandboxes, routines, actions and vault, on the machine that runs the model.
5
5
  Project-URL: Documentation, https://docs.beta.b3os.org
6
6
  Project-URL: Source, https://github.com/b3-fun/b3os-beta
@@ -214,8 +214,15 @@ for py in 3.10 3.12; do # the oldest supported Python a
214
214
  uv run --python $py --frozen --extra dev mypy --strict tests/typing_check.py # the types users see
215
215
  uv run --python $py --frozen --extra dev pytest -q # unit tests + Prism contract test (B3OS_PRISM=0 skips it)
216
216
  done
217
+ bash scripts/import-smoke.sh # what CI runs: the package imports, every signature resolves
217
218
  ```
218
219
 
220
+ A parameter name Python cannot spell as an argument is renamed in the generated method, and the request still
221
+ sends the spec's name: a keyword gets a `_` behind (`from_`), other characters become `_` (`max-age` is `max_age`),
222
+ a leading digit gets a `_` in front (`2fa` is `_2fa`), and a name the method uses itself (`self`, `options`, `body`,
223
+ `stream`) gets a `_` behind. The method's docstring lists each renamed argument.
224
+
219
225
  The unit tests include trio runs of `AsyncB3OS` (trio is a dev dependency).
220
226
 
221
- The live test runs on dev-h200 against a dev b3osd: `ops/box.sh sdk -- bash packages/sdk/test/live/run.sh py`.
227
+ The live test runs on dev-h200 against a dev b3osd:
228
+ `B3OS_NODE=n1 ops/box.sh sdk -- bash packages/sdk/test/live/run.sh py`.
@@ -188,8 +188,15 @@ for py in 3.10 3.12; do # the oldest supported Python a
188
188
  uv run --python $py --frozen --extra dev mypy --strict tests/typing_check.py # the types users see
189
189
  uv run --python $py --frozen --extra dev pytest -q # unit tests + Prism contract test (B3OS_PRISM=0 skips it)
190
190
  done
191
+ bash scripts/import-smoke.sh # what CI runs: the package imports, every signature resolves
191
192
  ```
192
193
 
194
+ A parameter name Python cannot spell as an argument is renamed in the generated method, and the request still
195
+ sends the spec's name: a keyword gets a `_` behind (`from_`), other characters become `_` (`max-age` is `max_age`),
196
+ a leading digit gets a `_` in front (`2fa` is `_2fa`), and a name the method uses itself (`self`, `options`, `body`,
197
+ `stream`) gets a `_` behind. The method's docstring lists each renamed argument.
198
+
193
199
  The unit tests include trio runs of `AsyncB3OS` (trio is a dev dependency).
194
200
 
195
- The live test runs on dev-h200 against a dev b3osd: `ops/box.sh sdk -- bash packages/sdk/test/live/run.sh py`.
201
+ The live test runs on dev-h200 against a dev b3osd:
202
+ `B3OS_NODE=n1 ops/box.sh sdk -- bash packages/sdk/test/live/run.sh py`.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "b3os"
3
- version = "0.2.2"
3
+ version = "0.2.3"
4
4
  description = "Python SDK for B3OS beta: vision (web pages and browsers), render, infer, sandboxes, routines, actions and vault, on the machine that runs the model."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env bash
2
+ # The generated Python SDK must import (B3-7269). A spec name the generator turned into an argument Python cannot
3
+ # parse (`from` on workspaces diff, #327) made `import b3os` a SyntaxError on main, and CI never imported the
4
+ # package. This runs scripts/import_smoke.py twice, in a fresh environment with only the runtime dependencies:
5
+ #
6
+ # 1. on the package as committed: every module imports, both clients build, every namespace method's signature
7
+ # (overloads too) resolves, and every operation in _generated/ops.py has a sync and an async method;
8
+ # 2. on the package generated from the spec plus the names fixture (packages/sdk/scripts/py-names-fixture.mjs:
9
+ # keywords, dashes, dots, leading digits, names the methods use themselves), the same checks, and the fixture's
10
+ # renamed arguments must send the spec's names on the wire.
11
+ #
12
+ # The Checks workflow's gen-all job runs it on CI's Python (UV_PYTHON, 3.12 there; 3.12 by default here).
13
+ # Needs uv and Node 24+ (the fixture generator imports only the SDK generator's own modules). Leaves the package's
14
+ # .venv alone: the environment lives in a temporary directory removed on exit.
15
+ #
16
+ # Usage: bash packages/sdk-python/scripts/import-smoke.sh
17
+ set -euo pipefail
18
+ cd "$(dirname "$0")/.."
19
+
20
+ tmp=$(mktemp -d "${RUNNER_TEMP:-${TMPDIR:-/tmp}}/b3os-import-smoke.XXXXXX")
21
+ trap 'rm -rf "$tmp"' EXIT
22
+
23
+ export UV_PROJECT_ENVIRONMENT="$tmp/venv"
24
+ uv sync --locked --quiet --python "${UV_PYTHON:-3.12}"
25
+ py="$tmp/venv/bin/python"
26
+ "$py" -I -c 'import sys, b3os; print(f"import smoke: import b3os ok on Python {sys.version.split()[0]}")'
27
+ "$py" -I scripts/import_smoke.py
28
+
29
+ node ../sdk/scripts/py-names-fixture.mjs "$tmp/fixture"
30
+ "$py" -I scripts/import_smoke.py --path "$tmp/fixture" --fixture
@@ -0,0 +1,225 @@
1
+ """Imports the b3os package and resolves every generated method's signature (B3-7269).
2
+
3
+ A spec name the generator turns into an argument Python cannot parse (`from`, `class`, `max-age`) made
4
+ `import b3os` a SyntaxError on main once, and nothing in CI imported the package. This script, run by
5
+ scripts/import-smoke.sh in the Checks workflow, fails on that and on what a plain import does not reach:
6
+
7
+ 1. imports every module of the package;
8
+ 2. builds a sync and an async client and, on each, every namespace;
9
+ 3. evaluates the signature of every public namespace method, its overloads included, with the names the generated
10
+ modules import only for type checkers, so each annotation names a type that exists;
11
+ 4. checks that every operation in `_generated/ops.py` is called by a sync and an async method.
12
+
13
+ With `--fixture`, the package is the one packages/sdk/scripts/py-names-fixture.mjs writes, and the script also
14
+ calls its fixture operations through a mock transport: the renamed arguments (`from_`, `class_`, `max_age`) must
15
+ send the spec's names on the wire.
16
+
17
+ Usage, from packages/sdk-python in its environment (`uv sync --locked`):
18
+ python -I scripts/import_smoke.py the installed package (this checkout's src/b3os)
19
+ python -I scripts/import_smoke.py --path DIR --fixture the package at DIR/b3os
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import argparse
25
+ import asyncio
26
+ import importlib
27
+ import inspect
28
+ import keyword
29
+ import os
30
+ import pkgutil
31
+ import sys
32
+ import types
33
+ import typing
34
+ from typing import Any, Callable, Dict, Iterator, List, NoReturn, Sequence, Set
35
+
36
+
37
+ def fail(msg: str) -> NoReturn:
38
+ print(f"import smoke: {msg}", file=sys.stderr)
39
+ sys.exit(1)
40
+
41
+
42
+ def code_names(code: types.CodeType) -> Iterator[str]:
43
+ """Every name a function's code reads, nested lambdas and comprehensions included."""
44
+ yield from code.co_names
45
+ for c in code.co_consts:
46
+ if isinstance(c, types.CodeType):
47
+ yield from code_names(c)
48
+
49
+
50
+ def check_signature(where: str, fn: Any, ns: Dict[str, Any]) -> None:
51
+ overloads: Callable[[Any], Sequence[Any]] = getattr(typing, "get_overloads", lambda _f: []) # Python 3.11+
52
+ for i, f in enumerate([fn, *overloads(fn)]):
53
+ label = where if i == 0 else f"{where} (overload {i})"
54
+ try:
55
+ sig = inspect.signature(f, globals=ns, eval_str=True)
56
+ except Exception as e: # noqa: BLE001 - any failure to resolve an annotation is the finding
57
+ fail(f"{label}: the signature does not resolve: {type(e).__name__}: {e}")
58
+ for p in sig.parameters.values():
59
+ if not p.name.isidentifier() or keyword.iskeyword(p.name):
60
+ fail(f"{label}: argument {p.name!r} is not a Python identifier")
61
+
62
+
63
+ def check_client(client: Any, module: types.ModuleType, ns: Dict[str, Any], called: Set[str]) -> int:
64
+ count = 0
65
+ for attr, member in inspect.getmembers(type(client)):
66
+ if attr.startswith("_") or not hasattr(member, "func"):
67
+ continue # namespaces are cached properties; the rest (jobs, traces) is hand-written
68
+ namespace = getattr(client, attr)
69
+ cls = type(namespace)
70
+ if cls.__module__ != module.__name__:
71
+ continue
72
+ for name, fn in vars(cls).items():
73
+ if name.startswith("_") or not inspect.isfunction(fn):
74
+ continue
75
+ check_signature(f"{cls.__name__}.{name}", fn, ns)
76
+ called.update(code_names(fn.__code__))
77
+ count += 1
78
+ return count
79
+
80
+
81
+ def check_fixture(b3os: Any) -> None:
82
+ import httpx
83
+
84
+ seen: List[httpx.Request] = []
85
+
86
+ def handler(request: httpx.Request) -> httpx.Response:
87
+ seen.append(request)
88
+ if request.url.path.endswith("/events"):
89
+ return httpx.Response(200, text="data: {}\n\n", headers={"content-type": "text/event-stream"})
90
+ return httpx.Response(200, json={"from": "a", "class": "c", "max-age": 1})
91
+
92
+ http = httpx.Client(transport=httpx.MockTransport(handler))
93
+ with b3os.B3OS(api_key="b3os_sk_smoke", base_url="http://smoke.invalid", transport="http", http_client=http) as b3:
94
+ ws = b3.workspaces
95
+ ws.names_fixture(
96
+ "k1",
97
+ from_="f",
98
+ in_=2,
99
+ async_=True,
100
+ global_="g",
101
+ None_="n",
102
+ __debug___="d",
103
+ from__="f2",
104
+ max_age=5,
105
+ _2fa="t",
106
+ page_size=7,
107
+ _secret="s",
108
+ self_="me",
109
+ options_="o",
110
+ cast_="c",
111
+ str_="s2",
112
+ dict_="d2",
113
+ match="m",
114
+ type="ty",
115
+ list="l",
116
+ lambda_="L",
117
+ _3d_mode="z",
118
+ )
119
+ ws.names_fixture_body({"from": "x", "if": "y"}, body_="b", data="d", if_="i")
120
+ with ws.names_fixture_events(last_event_id_="e1", with_="w", last_event_id="7") as events:
121
+ for _ in events:
122
+ break
123
+ want_query = {
124
+ "from": "f",
125
+ "in": "2",
126
+ "global": "g",
127
+ "None": "n",
128
+ "__debug__": "d",
129
+ "from_": "f2",
130
+ "max-age": "5",
131
+ "2fa": "t",
132
+ "page.size": "7",
133
+ "__secret": "s",
134
+ "self": "me",
135
+ "options": "o",
136
+ "cast": "c",
137
+ "str": "s2",
138
+ "dict": "d2",
139
+ "match": "m",
140
+ "type": "ty",
141
+ "list": "l",
142
+ }
143
+ r = seen[0]
144
+ if r.url.path != "/v1/workspaces/k1/names-fixture":
145
+ fail(f"names_fixture: path {r.url.path}, want /v1/workspaces/k1/names-fixture")
146
+ got = dict(r.url.params)
147
+ for k, v in want_query.items():
148
+ if got.get(k) != v:
149
+ fail(f"names_fixture: query {k}={got.get(k)!r}, want {v!r} (all: {got})")
150
+ if got.get("async") not in ("true", "1", "True"):
151
+ fail(f"names_fixture: query async={got.get('async')!r}")
152
+ if r.headers.get("x-b3os-lambda") != "L" or r.headers.get("x-b3os-3d-mode") != "z":
153
+ fail(f"names_fixture: headers {dict(r.headers)}")
154
+ b = seen[1]
155
+ if dict(b.url.params) != {"body": "b", "data": "d", "if": "i"}:
156
+ fail(f"names_fixture_body: query {dict(b.url.params)}")
157
+ if b.content != b'{"from":"x","if":"y"}':
158
+ fail(f"names_fixture_body: body {b.content!r}")
159
+ e = seen[2]
160
+ if dict(e.url.params) != {"last_event_id": "e1", "with": "w"} or e.headers.get("last-event-id") != "7":
161
+ fail(f"names_fixture_events: query {dict(e.url.params)}, Last-Event-ID {e.headers.get('last-event-id')!r}")
162
+ print("import smoke: the fixture's renamed arguments send the spec's names")
163
+
164
+
165
+ def main() -> None:
166
+ ap = argparse.ArgumentParser(description=__doc__.split("\n")[0])
167
+ ap.add_argument("--path", help="import b3os from DIR/b3os instead of the installed package")
168
+ ap.add_argument("--fixture", action="store_true", help="also call the names fixture's operations")
169
+ args = ap.parse_args()
170
+ if args.path:
171
+ sys.path.insert(0, os.path.abspath(args.path))
172
+
173
+ import b3os
174
+
175
+ if args.path and not os.path.abspath(b3os.__file__).startswith(os.path.abspath(args.path) + os.sep):
176
+ fail(f"imported {b3os.__file__}, not the package under {args.path}")
177
+ for m in pkgutil.walk_packages(b3os.__path__, "b3os."):
178
+ importlib.import_module(m.name)
179
+
180
+ from b3os import _async, _sync, helpers
181
+ from b3os._generated import async_namespaces, clients, namespaces, types as gen_types
182
+ from b3os._generated import ops as gen_ops
183
+ from b3os._ops import Op
184
+
185
+ # The names the namespace modules import under `if TYPE_CHECKING:` (packages/sdk/scripts/gen/py.mjs).
186
+ checking = {
187
+ "_t": gen_types,
188
+ "_hs": helpers.sandboxes,
189
+ "B3OS": clients.B3OS,
190
+ "AsyncB3OS": clients.AsyncB3OS,
191
+ **{n: getattr(_sync, n) for n in ("ByteStream", "EventStream", "JobEventStream", "Page", "SyncCore")},
192
+ **{
193
+ n: getattr(_async, n)
194
+ for n in ("AsyncByteStream", "AsyncCore", "AsyncEventStream", "AsyncJobEventStream", "AsyncPage")
195
+ },
196
+ }
197
+ ops = {name for name, v in vars(gen_ops).items() if isinstance(v, Op)}
198
+ if not ops:
199
+ fail("_generated/ops.py defines no operations")
200
+
201
+ # A key and the plain HTTP transport, so neither client looks for a login or a node socket; nothing is sent.
202
+ sync_called: Set[str] = set()
203
+ with b3os.B3OS(api_key="b3os_sk_smoke", base_url="http://smoke.invalid", transport="http") as sync_client:
204
+ n_sync = check_client(sync_client, namespaces, {**vars(namespaces), **checking}, sync_called)
205
+ async_called: Set[str] = set()
206
+
207
+ async def check_async() -> int:
208
+ async with b3os.AsyncB3OS(api_key="b3os_sk_smoke", base_url="http://smoke.invalid", transport="http") as c:
209
+ return check_client(c, async_namespaces, {**vars(async_namespaces), **checking}, async_called)
210
+
211
+ n_async = asyncio.run(check_async())
212
+ for label, called in (("sync", sync_called), ("async", async_called)):
213
+ missing = sorted(ops - called)
214
+ if missing:
215
+ fail(f"no {label} method calls {len(missing)} operation(s): {', '.join(missing[:10])}")
216
+ print(
217
+ f"import smoke: b3os {getattr(b3os, '__version__', '?')} from {os.path.dirname(b3os.__file__)}: "
218
+ f"{n_sync} sync and {n_async} async methods resolve, covering {len(ops)} operations"
219
+ )
220
+ if args.fixture:
221
+ check_fixture(b3os)
222
+
223
+
224
+ if __name__ == "__main__":
225
+ main()