Skip to content

Commit 4a7a063

Browse files
authored
Python tests: load Pyodide bundle from disk cache (#5780)
Instead of repeatedly downloading it from the network.
1 parent 273d988 commit 4a7a063

File tree

2 files changed

+47
-14
lines changed

2 files changed

+47
-14
lines changed

build/deps/dep_pyodide.bzl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,18 @@ filegroup(
4242
url = VENDOR_R2 + name + pyver + "-vendored-for-ew-testing.zip",
4343
)
4444

45-
SNAPSHOT_R2 = "https://pyodide-capnp-bin.edgeworker.net/"
45+
PYODIDE_CAPN_BIN = "https://pyodide-capnp-bin.edgeworker.net/"
4646

47-
def _snapshot_http_file(bundle_name, folder, snapshot, integrity, hash, r2_base = SNAPSHOT_R2):
47+
def _capnp_bundle(id = None, integrity = None, **_kwds):
48+
if not id or not integrity:
49+
return
50+
http_file(
51+
name = "pyodide_%s.capnp.bin" % id,
52+
integrity = integrity,
53+
url = PYODIDE_CAPN_BIN + "pyodide_%s.capnp.bin" % id,
54+
)
55+
56+
def _snapshot_http_file(bundle_name, folder, snapshot, integrity, hash, r2_base = PYODIDE_CAPN_BIN):
4857
if not snapshot:
4958
return
5059
if not integrity:
@@ -81,6 +90,7 @@ def dep_pyodide():
8190
_pyodide_core(**info)
8291

8392
for info in BUNDLE_VERSION_INFO.values():
93+
_capnp_bundle(**info)
8494
for pkg in info["vendored_packages_for_tests"].values():
8595
_py_vendor_test_deps(version = info["name"], **pkg)
8696

src/workerd/server/tests/python/py_wd_test.bzl

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,44 @@ def _snapshot_file(snapshot):
8181
return [":" + snapshot]
8282

8383
def _snapshot_files(
84+
name,
8485
baseline_snapshot = None,
8586
numpy_snapshot = None,
8687
fastapi_snapshot = None,
8788
dedicated_fastapi_snapshot = None,
8889
**_kwds):
90+
if name == "development":
91+
return []
8992
result = []
9093
result += _snapshot_file(baseline_snapshot)
9194
result += _snapshot_file(numpy_snapshot)
9295
result += _snapshot_file(fastapi_snapshot)
9396
result += _snapshot_file(dedicated_fastapi_snapshot)
9497
return result
9598

96-
def python_test_setup():
99+
def _snapshot_file_group():
100+
snapshots = []
101+
for x in BUNDLE_VERSION_INFO.values():
102+
snapshots += _snapshot_files(**x)
103+
104+
native.filegroup(
105+
name = "python_snapshots",
106+
data = snapshots,
107+
visibility = ["//visibility:public"],
108+
)
109+
110+
def _capnp_bundle(id, **_kwds):
111+
if id == "dev":
112+
return
113+
name = "pyodide_%s.capnp.bin" % id
114+
copy_file(
115+
name = name + "@rule",
116+
src = "@%s//file" % name,
117+
out = "pyodide-bundle-cache/" + name,
118+
visibility = ["//visibility:public"],
119+
)
120+
121+
def _capnp_bundles_file_group():
97122
# pyodide_dev.capnp.bin represents a custom pyodide version "dev" that is generated
98123
# at build time using the latest contents of the src/pyodide directory.
99124
# This is used to run tests to ensure that they are always run against the latest build of
@@ -104,17 +129,15 @@ def python_test_setup():
104129
out = "pyodide-bundle-cache/pyodide_dev.capnp.bin",
105130
visibility = ["//visibility:public"],
106131
)
107-
data = []
108-
for x in BUNDLE_VERSION_INFO.values():
109-
if x["name"] == "development":
110-
continue
111-
data += _snapshot_files(**x)
132+
for info in BUNDLE_VERSION_INFO.values():
133+
_capnp_bundle(**info)
112134

113-
native.filegroup(
114-
name = "python_snapshots",
115-
data = data,
116-
visibility = ["//visibility:public"],
117-
)
135+
def _capnp_rules():
136+
return ["//src/workerd/server/tests/python:pyodide_%s.capnp.bin@rule" % info["id"] for info in BUNDLE_VERSION_INFO.values()]
137+
138+
def python_test_setup():
139+
_capnp_bundles_file_group()
140+
_snapshot_file_group()
118141

119142
def compute_python_flags(python_flags, skip_python_flags):
120143
if python_flags == "all":
@@ -154,7 +177,7 @@ def py_wd_test(
154177
name = directory
155178
elif name == None:
156179
name = src.removesuffix(".wd-test")
157-
data += ["//src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule"]
180+
data += _capnp_rules()
158181
args = args + [
159182
"--pyodide-bundle-disk-cache-dir",
160183
"$(location //src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule)/..",

0 commit comments

Comments
 (0)