Skip to content

Commit 7fad27a

Browse files
committed
Python tests: load Pyodide bundle from disk cache
Instead of repeatedly downloading it from the network.
1 parent 4a2c693 commit 7fad27a

File tree

2 files changed

+48
-14
lines changed

2 files changed

+48
-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/"
46+
def _capnp_bundle(id = None, integrity = None, **_kwds):
47+
if not id or not integrity:
48+
return
49+
http_file(
50+
name = "pyodide_%s.capnp.bin" % id,
51+
integrity = integrity,
52+
url = PYODIDE_CAPN_BIN + "pyodide_%s.capnp.bin" % id,
53+
)
54+
4655

47-
def _snapshot_http_file(bundle_name, folder, snapshot, integrity, hash, r2_base = SNAPSHOT_R2):
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: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,45 @@ 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+
111+
def _capnp_bundle(id, **_kwds):
112+
if id == "dev":
113+
return
114+
name = "pyodide_%s.capnp.bin" % id
115+
copy_file(
116+
name = name + "@rule",
117+
src = "@%s//file" % name,
118+
out = "pyodide-bundle-cache/" + name,
119+
visibility = ["//visibility:public"],
120+
)
121+
122+
def _capnp_bundles_file_group():
97123
# pyodide_dev.capnp.bin represents a custom pyodide version "dev" that is generated
98124
# at build time using the latest contents of the src/pyodide directory.
99125
# This is used to run tests to ensure that they are always run against the latest build of
@@ -104,17 +130,15 @@ def python_test_setup():
104130
out = "pyodide-bundle-cache/pyodide_dev.capnp.bin",
105131
visibility = ["//visibility:public"],
106132
)
107-
data = []
108-
for x in BUNDLE_VERSION_INFO.values():
109-
if x["name"] == "development":
110-
continue
111-
data += _snapshot_files(**x)
133+
for info in BUNDLE_VERSION_INFO.values():
134+
_capnp_bundle(**info)
112135

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

119143
def compute_python_flags(python_flags, skip_python_flags):
120144
if python_flags == "all":
@@ -154,7 +178,7 @@ def py_wd_test(
154178
name = directory
155179
elif name == None:
156180
name = src.removesuffix(".wd-test")
157-
data += ["//src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule"]
181+
data += _capnp_rules()
158182
args = args + [
159183
"--pyodide-bundle-disk-cache-dir",
160184
"$(location //src/workerd/server/tests/python:pyodide_dev.capnp.bin@rule)/..",

0 commit comments

Comments
 (0)