@@ -53,38 +53,6 @@ def _capnp_bundle(id = None, integrity = None, **_kwds):
5353 url = PYODIDE_CAPN_BIN + "pyodide_%s.capnp.bin" % id ,
5454 )
5555
56- def _snapshot_http_file (bundle_name , folder , snapshot , integrity , hash , r2_base = PYODIDE_CAPN_BIN ):
57- if not snapshot :
58- return
59- if not integrity :
60- fail ("Snapshot %s from bundle %s has missing integrity" % (snapshot , bundle_name ))
61- if folder == "baseline-snapshot/" :
62- key = hash
63- else :
64- key = snapshot
65- http_file (
66- name = "pyodide-snapshot-" + snapshot ,
67- integrity = integrity ,
68- url = r2_base + folder + key ,
69- )
70-
71- def _snapshot_http_files (
72- name ,
73- baseline_snapshot = None ,
74- baseline_snapshot_hash = None ,
75- baseline_snapshot_integrity = None ,
76- numpy_snapshot = None ,
77- numpy_snapshot_integrity = None ,
78- fastapi_snapshot = None ,
79- fastapi_snapshot_integrity = None ,
80- dedicated_fastapi_snapshot = None ,
81- dedicated_fastapi_snapshot_integrity = None ,
82- ** _kwds ):
83- _snapshot_http_file (name , "baseline-snapshot/" , baseline_snapshot , baseline_snapshot_integrity , baseline_snapshot_hash )
84- _snapshot_http_file (name , "test-snapshot/" , numpy_snapshot , numpy_snapshot_integrity , None )
85- _snapshot_http_file (name , "test-snapshot/" , fastapi_snapshot , fastapi_snapshot_integrity , None )
86- _snapshot_http_file (name , "" , dedicated_fastapi_snapshot , dedicated_fastapi_snapshot_integrity , None , VENDOR_R2 )
87-
8856def dep_pyodide ():
8957 for info in PYODIDE_VERSIONS :
9058 _pyodide_core (** info )
@@ -97,5 +65,50 @@ def dep_pyodide():
9765 for info in PYTHON_LOCKFILES :
9866 _pyodide_packages (** info )
9967
68+ # Accumulator to de-duplicate generated http_file rules.
69+ gen_http_file = {}
70+
71+ def _snapshot_http_files (
72+ name ,
73+ baseline_snapshot = None ,
74+ baseline_snapshot_hash = None ,
75+ baseline_snapshot_integrity = None ,
76+ numpy_snapshot = None ,
77+ numpy_snapshot_integrity = None ,
78+ fastapi_snapshot = None ,
79+ fastapi_snapshot_integrity = None ,
80+ dedicated_fastapi_snapshot = None ,
81+ dedicated_fastapi_snapshot_integrity = None ,
82+ ** _kwds ):
83+ def _snapshot_http_file (bundle_name , folder , snapshot , integrity , hash , r2_base = PYODIDE_CAPN_BIN ):
84+ if not snapshot :
85+ return
86+ if not integrity :
87+ fail ("Snapshot %s from bundle %s has missing integrity" % (snapshot , bundle_name ))
88+ if folder == "baseline-snapshot/" :
89+ key = hash
90+ else :
91+ key = snapshot
92+ gen_http_file [snapshot ] = struct (
93+ integrity = integrity ,
94+ url = r2_base + folder + key ,
95+ )
96+
97+ _snapshot_http_file (name , "baseline-snapshot/" , baseline_snapshot , baseline_snapshot_integrity , baseline_snapshot_hash )
98+ _snapshot_http_file (name , "test-snapshot/" , numpy_snapshot , numpy_snapshot_integrity , None )
99+ _snapshot_http_file (name , "test-snapshot/" , fastapi_snapshot , fastapi_snapshot_integrity , None )
100+ _snapshot_http_file (name , "" , dedicated_fastapi_snapshot , dedicated_fastapi_snapshot_integrity , None , VENDOR_R2 )
101+
100102 for ver in BUNDLE_VERSION_INFO .values ():
101103 _snapshot_http_files (** ver )
104+ for snapshot , info in gen_http_file .items ():
105+ http_file (
106+ name = "pyodide-snapshot-" + snapshot ,
107+ integrity = info .integrity ,
108+ url = info .url ,
109+ )
110+
111+ def _impl (module_ctx ):
112+ dep_pyodide ()
113+
114+ pyodide = module_extension (implementation = _impl )
0 commit comments