Skip to content

Commit c5c3615

Browse files
committed
Remove more unicocde
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent 175f8ce commit c5c3615

10 files changed

Lines changed: 105 additions & 105 deletions

src/sdk/python/core/examples/benchmark.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
COLD_ROUNDS = 5 # tests that create a new sandbox each time
1717
WARM_ROUNDS = 10 # tests that reuse an existing sandbox
1818

19-
# ── Helpers ──────────────────────────────────────────────────────────
19+
# -- Helpers ----------------------------------------------------------
2020

2121

2222
def measure_n(fn, n):
@@ -32,7 +32,7 @@ def measure_n(fn, n):
3232

3333

3434
def fmt(stats):
35-
"""Format stats as 'avg ms (min=, max=)'."""
35+
"""Format stats as 'avg ms (min=..., max=...)'."""
3636
return f"{stats['avg']:>7.1f} ms (min={stats['min']:.1f}, max={stats['max']:.1f})"
3737

3838

@@ -45,9 +45,9 @@ def run_suite(name, backend, module=None, lang="python"):
4545
"""Run all benchmarks for one backend configuration."""
4646
from hyperlight_sandbox import Sandbox
4747

48-
print(f"\n{'' * 70}")
48+
print(f"\n{'=' * 70}")
4949
print(f" {name} ({COLD_ROUNDS} cold / {WARM_ROUNDS} warm rounds)")
50-
print(f"{'' * 70}")
50+
print(f"{'=' * 70}")
5151

5252
hello = 'print("hello")' if lang == "python" else 'console.log("hello")'
5353
tool_code = (
@@ -67,7 +67,7 @@ def run_suite(name, backend, module=None, lang="python"):
6767

6868
results = {}
6969

70-
# ── 1. Cold start: create + first run ────────────────────────
70+
# -- 1. Cold start: create + first run ------------------------
7171
def cold_start():
7272
s = Sandbox(**kwargs)
7373
r = s.run(hello)
@@ -78,12 +78,12 @@ def cold_start():
7878
results["Cold start (create + first run)"] = stats
7979
print(f" Cold start (create + first run): {fmt(stats)}")
8080

81-
# ── 2. Warm run (no restore) ───────────────────────────────
81+
# -- 2. Warm run (no restore) -------------------------------
8282
_, stats = measure_n(lambda: sandbox.run(hello), WARM_ROUNDS)
8383
results["Warm run (no restore)"] = stats
8484
print(f" Warm run (no restore): {fmt(stats)}")
8585

86-
# ── 3. Cold start + tool dispatch ────────────────────────────
86+
# -- 3. Cold start + tool dispatch ----------------------------
8787
def with_tools():
8888
s = Sandbox(**kwargs)
8989
s.register_tool("add", lambda a=0, b=0: a + b)
@@ -95,15 +95,15 @@ def with_tools():
9595
results["Cold start + tool dispatch"] = stats
9696
print(f" Cold start + tool dispatch: {fmt(stats)}")
9797

98-
# ── 4. Warm tool dispatch (no restore) ────────────────────────
98+
# -- 4. Warm tool dispatch (no restore) ------------------------
9999
warm_tool_sandbox = Sandbox(**kwargs)
100100
warm_tool_sandbox.register_tool("add", lambda a=0, b=0: a + b)
101101
warm_tool_sandbox.run(hello) # warm up
102102
_, stats = measure_n(lambda: warm_tool_sandbox.run(tool_code), WARM_ROUNDS)
103103
results["Warm tool dispatch (no restore)"] = stats
104104
print(f" Warm tool dispatch (no restore): {fmt(stats)}")
105105

106-
# ── 5. File I/O ──────────────────────────────────────────────
106+
# -- 5. File I/O ----------------------------------------------
107107
if file_code:
108108

109109
def with_files():
@@ -127,7 +127,7 @@ def with_files():
127127
results["Warm file I/O (no restore)"] = None
128128
print(" File I/O: n/a (not supported)")
129129

130-
# ── 6. Snapshot (create sandbox, run, then time just the snapshot) ──
130+
# -- 6. Snapshot (create sandbox, run, then time just the snapshot) --
131131
def one_snapshot():
132132
s = Sandbox(**kwargs)
133133
s.register_tool("add", lambda a=0, b=0: a + b)
@@ -145,7 +145,7 @@ def one_snapshot():
145145
results["Snapshot"] = stats
146146
print(f" Snapshot: {fmt(stats)}")
147147

148-
# ── 7. Restore (create sandbox, snapshot, then time just the restore) ──
148+
# -- 7. Restore (create sandbox, snapshot, then time just the restore) --
149149
def one_restore():
150150
s = Sandbox(**kwargs)
151151
s.register_tool("add", lambda a=0, b=0: a + b)
@@ -164,7 +164,7 @@ def one_restore():
164164
results["Restore"] = stats
165165
print(f" Restore: {fmt(stats)}")
166166

167-
# ── 8. Restore + run ─────────────────────────────────────────
167+
# -- 8. Restore + run -----------------------------------------
168168
snap_sandbox = Sandbox(**kwargs)
169169
snap_sandbox.register_tool("add", lambda a=0, b=0: a + b)
170170
snap_sandbox.run(hello)
@@ -179,7 +179,7 @@ def restore_and_run():
179179
results["Restore + run"] = stats
180180
print(f" Restore + run: {fmt(stats)}")
181181

182-
# ── 9. Restore + tool dispatch ───────────────────────────────
182+
# -- 9. Restore + tool dispatch -------------------------------
183183
def restore_and_tool():
184184
snap_sandbox.restore(snap)
185185
return snap_sandbox.run(tool_code)
@@ -191,7 +191,7 @@ def restore_and_tool():
191191
return results
192192

193193

194-
# ── Main ─────────────────────────────────────────────────────────────
194+
# -- Main -------------------------------------------------------------
195195

196196

197197
def main():
@@ -218,28 +218,28 @@ def main():
218218
except Exception as e:
219219
print(f" [warn] Skipped: {e}")
220220

221-
# ── Summary table (averages) ─────────────────────────────────
221+
# -- Summary table (averages) ---------------------------------
222222
if all_results:
223-
print(f"\n{'' * 90}")
223+
print(f"\n{'=' * 90}")
224224
print(" Summary (avg ms)")
225-
print(f"{'' * 90}")
225+
print(f"{'=' * 90}")
226226

227227
backends = list(all_results.keys())
228228
steps = list(next(iter(all_results.values())).keys())
229229

230230
header = f"{'Step':<35}" + "".join(f"{b:>18}" for b in backends)
231231
print(header)
232-
print("" * len(header))
232+
print("-" * len(header))
233233
for step in steps:
234234
row = f"{step:<35}"
235235
for b in backends:
236236
s = all_results[b].get(step)
237237
row += f"{fmt_short(s) if s else 'n/a':>18}"
238238
print(row)
239239

240-
print(f"\n{'' * 90}")
240+
print(f"\n{'=' * 90}")
241241
print(f" Done! ({COLD_ROUNDS} cold / {WARM_ROUNDS} warm rounds per test)")
242-
print(f"{'' * 90}")
242+
print(f"{'=' * 90}")
243243

244244

245245
if __name__ == "__main__":

src/sdk/python/core/examples/javascript_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Hyperlight Sandbox JavaScript basics example (HyperlightJS backend).
1+
"""Hyperlight Sandbox -- JavaScript basics example (HyperlightJS backend).
22
33
Exercises: basic execution, tool dispatch, snapshot/restore, complex
44
computation, and nested tool calls.

src/sdk/python/core/examples/javascript_filesystem_demo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88

99
def separator(label: str) -> None:
10-
print(f"\n── {label} ──")
10+
print(f"\n-- {label} --")
1111

1212

13-
# ── Test 1: No filesystem ────────────────────────────────────────────
13+
# -- Test 1: No filesystem --------------------------------------------
1414
separator("Test 1: No filesystem")
1515
sandbox = Sandbox(backend="hyperlight-js")
1616
result = sandbox.run("console.log('no filesystem needed');")
@@ -20,7 +20,7 @@ def separator(label: str) -> None:
2020
assert len(outputs) == 0
2121
print("OK: runs without filesystem")
2222

23-
# ── Test 2: Input only ───────────────────────────────────────────────
23+
# -- Test 2: Input only -----------------------------------------------
2424
separator("Test 2: Input only")
2525
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
2626
with open(os.path.join(input_dir, "greeting.txt"), "w") as f:
@@ -32,7 +32,7 @@ def separator(label: str) -> None:
3232
assert "hello from host" in result.stdout
3333
print("OK: guest reads input")
3434

35-
# ── Test 3: Temp output only ─────────────────────────────────────────
35+
# -- Test 3: Temp output only -----------------------------------------
3636
separator("Test 3: Temp output only")
3737
sandbox = Sandbox(backend="hyperlight-js", temp_output=True)
3838
result = sandbox.run("write_file('/output/result.txt', 'js output'); console.log('wrote');")
@@ -44,7 +44,7 @@ def separator(label: str) -> None:
4444
assert f.read() == b"js output"
4545
print("OK: guest writes to temp output")
4646

47-
# ── Test 4: Input + temp output ──────────────────────────────────────
47+
# -- Test 4: Input + temp output --------------------------------------
4848
separator("Test 4: Input + temp output")
4949
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
5050
with open(os.path.join(input_dir, "data.json"), "w") as f:
@@ -65,7 +65,7 @@ def separator(label: str) -> None:
6565
assert f.read() == b"42"
6666
print("OK: reads input, writes output")
6767

68-
# ── Test 5: Explicit output dir ──────────────────────────────────────
68+
# -- Test 5: Explicit output dir --------------------------------------
6969
separator("Test 5: Explicit output dir")
7070
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
7171
output_dir = tempfile.mkdtemp(prefix="sandbox-output-")
@@ -83,7 +83,7 @@ def separator(label: str) -> None:
8383
assert f.read() == "SHOUT"
8484
print("OK: output visible on host filesystem")
8585

86-
# ── Test 6: Output wiped between runs ────────────────────────────────
86+
# -- Test 6: Output wiped between runs --------------------------------
8787
separator("Test 6: Output is ephemeral")
8888
sandbox = Sandbox(backend="hyperlight-js", temp_output=True)
8989
result = sandbox.run("write_file('/output/run1.txt', 'first');")
@@ -96,7 +96,7 @@ def separator(label: str) -> None:
9696
assert "run2.txt" in outputs
9797
print("OK: output wiped between runs")
9898

99-
# ── Test 7: Input is read-only ───────────────────────────────────────
99+
# -- Test 7: Input is read-only ---------------------------------------
100100
separator("Test 7: Input is read-only")
101101
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
102102
with open(os.path.join(input_dir, "readonly.txt"), "w") as f:
Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Hyperlight Sandbox JavaScript network access demo (HyperlightJS backend).
1+
"""Hyperlight Sandbox -- JavaScript network access demo (HyperlightJS backend).
22
33
Tests network deny-by-default and allow-listed domain access.
44
"""
@@ -15,31 +15,31 @@
1515

1616
sandbox.allow_domain("https://httpbin.org", methods=["GET"])
1717

18-
# ═══════════════════════════════════════════════════════════════════
19-
# Test 1: Network access blocked by default
20-
# ═══════════════════════════════════════════════════════════════════
21-
print("" * 60)
18+
# ===================================================================
19+
# Test 1: Network access -- blocked by default
20+
# ===================================================================
21+
print("=" * 60)
2222
print("Test 1: Network access denied without permissions")
23-
print("" * 60)
23+
print("=" * 60)
2424
result = sandbox.run("""
2525
const resp = await fetch('https://notallowed.example');
2626
if (resp.status === 403) {
2727
console.log('Network blocked: status ' + resp.status);
28-
console.log(' (notallowed.example is not in the allowlist correct!)');
28+
console.log(' (notallowed.example is not in the allowlist -- correct!)');
2929
} else {
3030
console.log('Got response: ' + resp.status);
3131
}
3232
""")
3333
print(result.stdout)
3434
assert "Network blocked" in result.stdout, "test 1: expected network access to be blocked"
3535

36-
# ═══════════════════════════════════════════════════════════════════
37-
# Test 2: Network access allowed domain
38-
# ═══════════════════════════════════════════════════════════════════
36+
# ===================================================================
37+
# Test 2: Network access -- allowed domain
38+
# ===================================================================
3939
print()
40-
print("" * 60)
40+
print("=" * 60)
4141
print("Test 2: Network access to allowed domain")
42-
print("" * 60)
42+
print("=" * 60)
4343
result = sandbox.run("""
4444
const resp = await fetch('https://httpbin.org/get');
4545
const body = await resp.text();
@@ -50,13 +50,13 @@
5050
print(result.stdout)
5151
assert result.success, f"test 2: network access to allowed domain failed\nstderr: {result.stderr[:300]}"
5252

53-
# ═══════════════════════════════════════════════════════════════════
54-
# Test 3: Method filtering GET allowed, POST blocked
55-
# ═══════════════════════════════════════════════════════════════════
53+
# ===================================================================
54+
# Test 3: Method filtering -- GET allowed, POST blocked
55+
# ===================================================================
5656
print()
57-
print("" * 60)
58-
print("Test 3: Method filtering GET allowed, POST blocked")
59-
print("" * 60)
57+
print("=" * 60)
58+
print("Test 3: Method filtering -- GET allowed, POST blocked")
59+
print("=" * 60)
6060
result = sandbox.run("""
6161
const getResp = await fetch('https://httpbin.org/get');
6262
if (getResp.status === 200) {
@@ -69,14 +69,14 @@
6969
const postResp = await fetch('https://httpbin.org/post', { method: 'POST' });
7070
if (postResp.status === 403) {
7171
console.log('POST blocked: status ' + postResp.status);
72-
console.log(' (httpbin.org only allows GET correct!)');
72+
console.log(' (httpbin.org only allows GET -- correct!)');
7373
} else {
7474
console.log('POST allowed: status ' + postResp.status);
7575
}
7676
""")
7777
print(result.stdout)
7878
assert "POST blocked" in result.stdout, "test 3: expected POST to be blocked"
7979

80-
print("" * 60)
80+
print("=" * 60)
8181
print("[ok] All tests passed!")
82-
print("" * 60)
82+
print("=" * 60)

src/sdk/python/core/examples/jswasm_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Hyperlight Sandbox JS Wasm component basics example (Python SDK).
1+
"""Hyperlight Sandbox -- JS Wasm component basics example (Python SDK).
22
33
Exercises: basic execution, tool dispatch, snapshot/restore, complex
44
computation, and nested tool calls.

src/sdk/python/core/examples/jswasm_filesystem_demo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88

99
def separator(label: str) -> None:
10-
print(f"\n── {label} ──")
10+
print(f"\n-- {label} --")
1111

1212

13-
# ── Test 1: No filesystem ────────────────────────────────────────────
13+
# -- Test 1: No filesystem --------------------------------------------
1414
separator("Test 1: No filesystem")
1515
sandbox = Sandbox(backend="wasm", module="javascript_guest.path")
1616
result = sandbox.run("console.log('no filesystem needed');")
@@ -20,7 +20,7 @@ def separator(label: str) -> None:
2020
assert len(outputs) == 0
2121
print("OK: runs without filesystem")
2222

23-
# ── Test 2: Input only ───────────────────────────────────────────────
23+
# -- Test 2: Input only -----------------------------------------------
2424
separator("Test 2: Input only")
2525
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
2626
with open(os.path.join(input_dir, "greeting.txt"), "w") as f:
@@ -32,7 +32,7 @@ def separator(label: str) -> None:
3232
assert "hello from host" in result.stdout
3333
print("OK: guest reads input")
3434

35-
# ── Test 3: Temp output only ─────────────────────────────────────────
35+
# -- Test 3: Temp output only -----------------------------------------
3636
separator("Test 3: Temp output only")
3737
sandbox = Sandbox(backend="wasm", module="javascript_guest.path", temp_output=True)
3838
result = sandbox.run("write_file('/output/result.txt', 'js output'); console.log('wrote');")
@@ -44,7 +44,7 @@ def separator(label: str) -> None:
4444
assert f.read() == b"js output"
4545
print("OK: guest writes to temp output")
4646

47-
# ── Test 4: Input + temp output ──────────────────────────────────────
47+
# -- Test 4: Input + temp output --------------------------------------
4848
separator("Test 4: Input + temp output")
4949
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
5050
with open(os.path.join(input_dir, "data.json"), "w") as f:
@@ -65,7 +65,7 @@ def separator(label: str) -> None:
6565
assert f.read() == b"42"
6666
print("OK: reads input, writes output")
6767

68-
# ── Test 5: Explicit output dir ──────────────────────────────────────
68+
# -- Test 5: Explicit output dir --------------------------------------
6969
separator("Test 5: Explicit output dir")
7070
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
7171
output_dir = tempfile.mkdtemp(prefix="sandbox-output-")
@@ -83,7 +83,7 @@ def separator(label: str) -> None:
8383
assert f.read() == "SHOUT"
8484
print("OK: output visible on host filesystem")
8585

86-
# ── Test 6: Output wiped between runs ────────────────────────────────
86+
# -- Test 6: Output wiped between runs --------------------------------
8787
separator("Test 6: Output is ephemeral")
8888
sandbox = Sandbox(backend="wasm", module="javascript_guest.path", temp_output=True)
8989
result = sandbox.run("write_file('/output/run1.txt', 'first');")
@@ -96,7 +96,7 @@ def separator(label: str) -> None:
9696
assert "run2.txt" in outputs
9797
print("OK: output wiped between runs")
9898

99-
# ── Test 7: Input is read-only ───────────────────────────────────────
99+
# -- Test 7: Input is read-only ---------------------------------------
100100
separator("Test 7: Input is read-only")
101101
input_dir = tempfile.mkdtemp(prefix="sandbox-input-")
102102
with open(os.path.join(input_dir, "readonly.txt"), "w") as f:

0 commit comments

Comments
 (0)