Skip to content

Commit e0baeae

Browse files
authored
Simplify dep_pyodide (#5832)
Removes closures
1 parent 042fbb8 commit e0baeae

File tree

1 file changed

+52
-45
lines changed

1 file changed

+52
-45
lines changed

build/deps/dep_pyodide.bzl

Lines changed: 52 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ PYODIDE_CAPN_BIN = "https://pyodide-capnp-bin.edgeworker.net/"
5353

5454
def _capnp_bundle(id = None, integrity = None, **_kwds):
5555
if not id or not integrity:
56-
return
56+
return []
5757
name = "pyodide_%s.capnp.bin" % id
5858
http_file(
5959
name = name,
@@ -62,6 +62,56 @@ def _capnp_bundle(id = None, integrity = None, **_kwds):
6262
)
6363
return [name]
6464

65+
def _snapshot_http_file(bundle_name, folder, snapshot, integrity, hash, r2_base = PYODIDE_CAPN_BIN):
66+
if not snapshot:
67+
return []
68+
if not integrity:
69+
fail("Snapshot %s from bundle %s has missing integrity" % (snapshot, bundle_name))
70+
if folder == "baseline-snapshot/":
71+
key = hash
72+
else:
73+
key = snapshot
74+
return [struct(
75+
name = "pyodide-snapshot-" + snapshot,
76+
snapshot = snapshot,
77+
integrity = integrity,
78+
url = r2_base + folder + key,
79+
)]
80+
81+
def _snapshot_http_files_version(
82+
name,
83+
baseline_snapshot = None,
84+
baseline_snapshot_hash = None,
85+
baseline_snapshot_integrity = None,
86+
numpy_snapshot = None,
87+
numpy_snapshot_integrity = None,
88+
fastapi_snapshot = None,
89+
fastapi_snapshot_integrity = None,
90+
dedicated_fastapi_snapshot = None,
91+
dedicated_fastapi_snapshot_integrity = None,
92+
**_kwds):
93+
return (_snapshot_http_file(name, "baseline-snapshot/", baseline_snapshot, baseline_snapshot_integrity, baseline_snapshot_hash) +
94+
_snapshot_http_file(name, "test-snapshot/", numpy_snapshot, numpy_snapshot_integrity, None) +
95+
_snapshot_http_file(name, "test-snapshot/", fastapi_snapshot, fastapi_snapshot_integrity, None) +
96+
_snapshot_http_file(name, "", dedicated_fastapi_snapshot, dedicated_fastapi_snapshot_integrity, None, VENDOR_R2))
97+
98+
def _snapshot_http_files():
99+
files = []
100+
for ver in BUNDLE_VERSION_INFO.values():
101+
files += _snapshot_http_files_version(**ver)
102+
103+
# Deduplicate generated http_file rules.
104+
http_files = {info.snapshot: info for info in files}
105+
deps = []
106+
for info in http_files.values():
107+
http_file(
108+
name = info.name,
109+
integrity = info.integrity,
110+
url = info.url,
111+
)
112+
deps.append(info.name)
113+
return deps
114+
65115
def dep_pyodide():
66116
deps = []
67117
for info in PYODIDE_VERSIONS:
@@ -75,50 +125,7 @@ def dep_pyodide():
75125
for info in PYTHON_LOCKFILES:
76126
deps += _pyodide_packages(**info)
77127

78-
# Accumulator to de-duplicate generated http_file rules.
79-
gen_http_file = {}
80-
81-
def _snapshot_http_files(
82-
name,
83-
baseline_snapshot = None,
84-
baseline_snapshot_hash = None,
85-
baseline_snapshot_integrity = None,
86-
numpy_snapshot = None,
87-
numpy_snapshot_integrity = None,
88-
fastapi_snapshot = None,
89-
fastapi_snapshot_integrity = None,
90-
dedicated_fastapi_snapshot = None,
91-
dedicated_fastapi_snapshot_integrity = None,
92-
**_kwds):
93-
def _snapshot_http_file(bundle_name, folder, snapshot, integrity, hash, r2_base = PYODIDE_CAPN_BIN):
94-
if not snapshot:
95-
return
96-
if not integrity:
97-
fail("Snapshot %s from bundle %s has missing integrity" % (snapshot, bundle_name))
98-
if folder == "baseline-snapshot/":
99-
key = hash
100-
else:
101-
key = snapshot
102-
gen_http_file[snapshot] = struct(
103-
integrity = integrity,
104-
url = r2_base + folder + key,
105-
)
106-
107-
_snapshot_http_file(name, "baseline-snapshot/", baseline_snapshot, baseline_snapshot_integrity, baseline_snapshot_hash)
108-
_snapshot_http_file(name, "test-snapshot/", numpy_snapshot, numpy_snapshot_integrity, None)
109-
_snapshot_http_file(name, "test-snapshot/", fastapi_snapshot, fastapi_snapshot_integrity, None)
110-
_snapshot_http_file(name, "", dedicated_fastapi_snapshot, dedicated_fastapi_snapshot_integrity, None, VENDOR_R2)
111-
112-
for ver in BUNDLE_VERSION_INFO.values():
113-
_snapshot_http_files(**ver)
114-
for snapshot, info in gen_http_file.items():
115-
name = "pyodide-snapshot-" + snapshot
116-
http_file(
117-
name = name,
118-
integrity = info.integrity,
119-
url = info.url,
120-
)
121-
deps.append(name)
128+
deps += _snapshot_http_files()
122129
return deps
123130

124131
def _impl(module_ctx):

0 commit comments

Comments
 (0)