solari-runloop-compat 0.1.3__tar.gz → 0.2.1__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.
Potentially problematic release.
This version of solari-runloop-compat might be problematic. Click here for more details.
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/LICENSE +1 -1
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/PKG-INFO +1 -1
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/pyproject.toml +1 -1
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/__init__.py +1 -1
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_gateway.py +17 -3
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_loop.py +5 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_sync.py +15 -3
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_gateway_wire.py +13 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_surface.py +72 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/.gitignore +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/BLUEPRINTS.md +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/COMPAT.md +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/GATEWAY-ENDPOINTS.md +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/NOTICE +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/README.md +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_branding.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_client.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_config.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_context.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_dockerfile.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_exceptions.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_mapping.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_models.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/_resources.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/lib/__init__.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/lib/polling.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/pagination.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/sdk.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/__init__.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/blueprint_build_log.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/blueprint_build_logs_list_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/blueprint_build_parameters.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/blueprint_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_async_execution_detail_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_execution_detail_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_snapshot_list_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_snapshot_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devboxes/__init__.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devboxes/devbox_logs_list_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/secret_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/__init__.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/after_idle.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/code_mount_parameters.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/launch_parameters.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/lifecycle_configuration.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/lifecycle_hooks.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/resume_triggers.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/tunnel_view.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/run_runloop_examples.sh +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_config.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_context.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_dockerfile.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_live_staging.py +0 -0
- {solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/tests/test_mapping.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "solari-runloop-compat"
|
|
7
|
-
version = "0.1
|
|
7
|
+
version = "0.2.1"
|
|
8
8
|
description = "Runloop-compatible Python interface over Solari Sandboxes. Not affiliated with Runloop."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -30,6 +30,19 @@ from .types import SecretView, BlueprintBuildLogsListView, BlueprintView, Devbox
|
|
|
30
30
|
|
|
31
31
|
log = logging.getLogger("solari_runloop")
|
|
32
32
|
|
|
33
|
+
|
|
34
|
+
def _short_id(sandbox_id: str) -> str:
|
|
35
|
+
"""Sandbox ids are capability tokens: logs carry the first 8 characters only."""
|
|
36
|
+
return f"{sandbox_id[:8]}…" if len(sandbox_id) > 8 else sandbox_id
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _redact(text: str, *sandbox_ids: str) -> str:
|
|
40
|
+
"""Replace every whole sandbox id in `text` (raw or URL-quoted, as it appears in request paths and exception messages) with its short form."""
|
|
41
|
+
for sid in sandbox_ids:
|
|
42
|
+
if len(sid) > 8:
|
|
43
|
+
text = text.replace(sid, _short_id(sid)).replace(quote(sid, safe=""), _short_id(sid))
|
|
44
|
+
return text
|
|
45
|
+
|
|
33
46
|
DEFAULT_KEEP_ALIVE_MS = 30 * 60_000
|
|
34
47
|
BIG_FILE_BYTES = 512 * 1024 # above this, files move over signed HTTP URLs instead of one control-channel frame
|
|
35
48
|
BUILTIN_TEMPLATES = {"base", "workstation", "ubuntu-desktop"}
|
|
@@ -261,8 +274,9 @@ class Gateway:
|
|
|
261
274
|
async def shutdown_quiet(self, devbox_id: str) -> None:
|
|
262
275
|
try:
|
|
263
276
|
await self.shutdown(devbox_id)
|
|
264
|
-
except Exception: # noqa: BLE001
|
|
265
|
-
|
|
277
|
+
except Exception as exc: # noqa: BLE001
|
|
278
|
+
# No traceback: exception messages carry request paths, and a path holds the whole id.
|
|
279
|
+
log.error("cleanup shutdown of %s failed: %s", _short_id(devbox_id), _redact(f"{type(exc).__name__}: {exc}", devbox_id))
|
|
266
280
|
|
|
267
281
|
async def suspend(self, devbox_id: str, polling: Optional[PollingConfig] = None) -> DevboxView:
|
|
268
282
|
await self._drop_handle(devbox_id)
|
|
@@ -571,7 +585,7 @@ class Gateway:
|
|
|
571
585
|
try:
|
|
572
586
|
rec.exit_code = await rec.handle.wait()
|
|
573
587
|
except Exception as e: # noqa: BLE001 - channel dropped before cmd.exit
|
|
574
|
-
log.warning("execution %s lost its control channel: %s", rec.execution_id, e)
|
|
588
|
+
log.warning("execution %s lost its control channel: %s", rec.execution_id, _redact(str(e), rec.devbox_id))
|
|
575
589
|
rec.exit_code = None
|
|
576
590
|
rec.flush()
|
|
577
591
|
rec.status = "completed"
|
|
@@ -8,6 +8,7 @@ that keeps running, so each sync client owns one daemon thread running a loop fo
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
10
|
import asyncio
|
|
11
|
+
import inspect
|
|
11
12
|
import threading
|
|
12
13
|
from typing import Any, Coroutine, Optional, TypeVar
|
|
13
14
|
|
|
@@ -44,6 +45,10 @@ class LoopThread:
|
|
|
44
45
|
def run(self, coro: "Coroutine[Any, Any, T]") -> T:
|
|
45
46
|
loop = self._ensure()
|
|
46
47
|
if self._thread is not None and threading.current_thread() is self._thread:
|
|
48
|
+
# The coroutine will never run: close it, or Python reports "coroutine ... was never awaited" when it is garbage
|
|
49
|
+
# collected, at a moment that depends on the collector (it surfaced as a failure in an unrelated test).
|
|
50
|
+
if inspect.iscoroutine(coro):
|
|
51
|
+
coro.close()
|
|
47
52
|
raise RuntimeError("sync solari_runloop API called from inside its own event loop (a streaming callback?)")
|
|
48
53
|
return asyncio.run_coroutine_threadsafe(coro, loop).result()
|
|
49
54
|
|
|
@@ -38,10 +38,22 @@ class SyncMirror:
|
|
|
38
38
|
res = attr(*a, **k)
|
|
39
39
|
if inspect.isawaitable(res):
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
started = False
|
|
42
|
+
inner_res = res
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
async def _await() -> Any:
|
|
45
|
+
nonlocal started
|
|
46
|
+
started = True
|
|
47
|
+
return await inner_res
|
|
48
|
+
|
|
49
|
+
try:
|
|
50
|
+
res = loop.run(_await())
|
|
51
|
+
except BaseException:
|
|
52
|
+
# Refused or failed before the loop ever ran it: close it so it is not left "never awaited". Once it has
|
|
53
|
+
# started (an interrupted or timed-out wait) it belongs to the loop thread and is left alone.
|
|
54
|
+
if not started and inspect.iscoroutine(inner_res):
|
|
55
|
+
inner_res.close()
|
|
56
|
+
raise
|
|
45
57
|
return wrap_result(res, loop)
|
|
46
58
|
|
|
47
59
|
return call
|
|
@@ -567,3 +567,16 @@ async def test_durable_exec_on_a_native_image_build_avoids_the_login_shell():
|
|
|
567
567
|
start = [c for c in s.calls if c[0] == "POST" and c[1].endswith("/executions")][0]
|
|
568
568
|
assert start[2]["cmd"] == "/bin/sh" and start[2]["args"][0] == "-c" and "-l" not in start[2]["args"][0]
|
|
569
569
|
assert "/bin/bash -c" in start[2]["args"][1] and start[2]["args"][-1] == g._remote_script()
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
@pytest.mark.asyncio
|
|
573
|
+
async def test_cleanup_shutdown_failure_never_logs_the_whole_id(caplog):
|
|
574
|
+
token = "AmByE367p4swyUL_N6WF5CiDMT9I4F4Xr3r.iVPUw-Zx82gtp3OkR5WDEvkHmuvgG06zp9S9zdDkV4M"
|
|
575
|
+
quoted = sr._gateway.quote(token, safe="")
|
|
576
|
+
g, _ = gw({("DELETE", "/sandboxes/"): RuntimeError(f"DELETE /sandboxes/{token} failed; retry /sandboxes/{quoted}")})
|
|
577
|
+
with caplog.at_level("ERROR", logger="solari_runloop"):
|
|
578
|
+
await g.shutdown_quiet(token)
|
|
579
|
+
text = caplog.text + "".join(r.getMessage() for r in caplog.records)
|
|
580
|
+
assert "AmByE367…" in text
|
|
581
|
+
assert token not in text and quoted not in text and token[:20] not in text
|
|
582
|
+
assert all(r.exc_info is None for r in caplog.records), "no traceback: exception messages carry the id"
|
|
@@ -4,6 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Any, Dict, List, Tuple
|
|
6
6
|
|
|
7
|
+
import asyncio
|
|
8
|
+
|
|
7
9
|
import pytest
|
|
8
10
|
|
|
9
11
|
import solari_runloop as sr
|
|
@@ -156,6 +158,35 @@ def test_sync_client_from_inside_its_loop_is_refused(fake):
|
|
|
156
158
|
client._loop.run(inner())
|
|
157
159
|
|
|
158
160
|
|
|
161
|
+
def test_a_refused_reentrant_call_leaves_no_coroutine_never_awaited(fake, recwarn):
|
|
162
|
+
"""The refused call used to leave its coroutine unawaited; Python reports that when the garbage collector gets to it, which made
|
|
163
|
+
the test above fail intermittently (and any strict-warnings run fail every time)."""
|
|
164
|
+
import gc
|
|
165
|
+
|
|
166
|
+
with sr.Runloop() as client:
|
|
167
|
+
loop = client._loop
|
|
168
|
+
|
|
169
|
+
async def reentrant():
|
|
170
|
+
coro = asyncio.sleep(0)
|
|
171
|
+
try:
|
|
172
|
+
loop.run(coro)
|
|
173
|
+
except RuntimeError as e:
|
|
174
|
+
return str(e), coro.cr_frame is None # a closed coroutine has no frame
|
|
175
|
+
return "no error", False
|
|
176
|
+
|
|
177
|
+
msg, closed = loop.run(reentrant())
|
|
178
|
+
assert "inside its own event loop" in msg
|
|
179
|
+
assert closed, "the refused coroutine is closed"
|
|
180
|
+
|
|
181
|
+
async def via_client():
|
|
182
|
+
client.devboxes.retrieve("d0")
|
|
183
|
+
|
|
184
|
+
with pytest.raises(RuntimeError, match="inside its own event loop"):
|
|
185
|
+
loop.run(via_client())
|
|
186
|
+
gc.collect()
|
|
187
|
+
assert not [w for w in recwarn if "never awaited" in str(w.message)], [str(w.message) for w in recwarn]
|
|
188
|
+
|
|
189
|
+
|
|
159
190
|
async def test_sdk_blueprint_create_deletes_the_template_when_the_build_fails(fake, monkeypatch):
|
|
160
191
|
deleted = []
|
|
161
192
|
|
|
@@ -181,3 +212,44 @@ async def test_sdk_blueprint_create_deletes_the_template_when_the_build_fails(fa
|
|
|
181
212
|
with pytest.raises(sr.RunloopError, match="build failed"):
|
|
182
213
|
await sdk.blueprint.create(name="n", dockerfile="FROM ubuntu\nRUN false")
|
|
183
214
|
assert deleted == ["tpl_x"]
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_an_interrupted_wait_keeps_its_error_and_leaves_the_running_coroutine_alone():
|
|
218
|
+
"""If the waiting thread is interrupted AFTER the loop started the call, the coroutine belongs to the loop thread: it must not be
|
|
219
|
+
closed (that raised "already executing" over the real error, or injected GeneratorExit into a coroutine the loop later resumes)."""
|
|
220
|
+
import asyncio
|
|
221
|
+
import threading
|
|
222
|
+
import time
|
|
223
|
+
|
|
224
|
+
from solari_runloop._loop import LoopThread
|
|
225
|
+
from solari_runloop._sync import SyncMirror
|
|
226
|
+
|
|
227
|
+
started = threading.Event()
|
|
228
|
+
finished = threading.Event()
|
|
229
|
+
|
|
230
|
+
class Inner:
|
|
231
|
+
_solari_mirror = True
|
|
232
|
+
|
|
233
|
+
async def slow(self):
|
|
234
|
+
started.set()
|
|
235
|
+
await asyncio.sleep(0.3)
|
|
236
|
+
finished.set()
|
|
237
|
+
return "done"
|
|
238
|
+
|
|
239
|
+
loop = LoopThread()
|
|
240
|
+
real_run = loop.run
|
|
241
|
+
|
|
242
|
+
def interrupted_run(coro):
|
|
243
|
+
fut = asyncio.run_coroutine_threadsafe(coro, loop._ensure())
|
|
244
|
+
assert started.wait(5)
|
|
245
|
+
del fut # the wait is abandoned, as a KeyboardInterrupt or a timeout would
|
|
246
|
+
raise KeyboardInterrupt("interrupted while the call was running")
|
|
247
|
+
|
|
248
|
+
loop.run = interrupted_run # type: ignore[method-assign]
|
|
249
|
+
mirror = SyncMirror(Inner(), loop)
|
|
250
|
+
with pytest.raises(KeyboardInterrupt):
|
|
251
|
+
mirror.slow()
|
|
252
|
+
loop.run = real_run # type: ignore[method-assign]
|
|
253
|
+
assert finished.wait(5), "the coroutine kept running on the loop thread and completed normally"
|
|
254
|
+
time.sleep(0.05)
|
|
255
|
+
loop.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/blueprint_view.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/devbox_view.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/secret_view.py
RENAMED
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/shared/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{solari_runloop_compat-0.1.3 → solari_runloop_compat-0.2.1}/solari_runloop/types/tunnel_view.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|